Trying to pass a random generated variable in one class to be used in another to sync up the background of my application and the header in another fragment.
public class LoginMain extends AppCompatActivity {
RelativeLayout loginMain;
Random rand = new Random();
int bgPick = rand.nextInt(5) + 1; //distribute int from 1 to 3;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_login_main);
//must be called after the content view is set.
loginMain = (RelativeLayout) findViewById(R.id.activity_login_main);
randomBG();//method that determines the background image based on the bgPick value.
}
public static int getBgPick(){
return bgPick;
}
Main Class:
public class MainActivity extends AppCompatActivity {
AppBarLayout appBarLayout;
int bgPick = LoginMain.getBgPick();
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
setSupportActionBar(toolbar);
appBarLayout = (AppBarLayout) findViewById(R.id.appbar);
randomHeader();//method to determine header image based on bgPick value determined in the LoginMain class.
This results in two bgPick values being made and used separately in each class.