Reputation:
Here is my question,my app flow is screen1,screen2,screen3.and their content views are like this:
screen1.java-->screen1.xml
screen2.java-->screen3.xml
screen3.java-->screen3.xml
here in screen1 if user clicks on toggle button to is going to screen2 then screen3 in screen3 payment success then only screen1 toggle button should change,how to achieve this,didn't get any idea,plz help me,Thanks.
Upvotes: 2
Views: 2625
Reputation: 1365
You can pass button state using Bundle between activities like following
Start activity 2
Intent intent = new Intent(this, Activity2.class);
intent.putExtra(EXTRA_NAME, VALUE);
startActivity(intent);
Get that value in activity 2 like
@Override
protected void onCreate(Bundle savedInstanceState) {
....
boolean value = getIntent().getExtras().getBoolean(EXTRA_VALUE);
}
same like above you can pass is to Activity 3.
Or
You can make a static variable in you Activity 1 and then access that from Activity 3.
Upvotes: 0
Reputation: 2889
You could also pass the toggle state via intents and onActivityResult().
Here is a video tutorial on intents
Here is some a tutorial on onActivityResult
Upvotes: 0
Reputation: 3255
You can make that toggle button static and then you can change its state from any activity.
static ToggleButton toggleButton = (ToggleButton)findViewById(R.id.toggle_btn);
but you need to be careful.
Upvotes: 0
Reputation: 5295
Use a static global array list and save the pressed states at their positions in that list. In the next activities use that array list to set the toggle status of your buttons
This is similarly like saving the checked states of a checkbox in a listview
Upvotes: 1
Reputation: 10100
You can save the state of toggle button in Shared preferences. Check this : Shared Preferences Android and Example
Hope this helps.
Upvotes: 1