1

My question is like in my activity 2 i have the screen like below. enter image description here

I am toggling two or more toggle button (activity 2) and going back(arrow) to activity 1. Now My question is how to save those value when navigating from activity 1 to activity 2 again for the second time with two or more toggle off.

Brijesh Kumar
  • 1,685
  • 2
  • 17
  • 28
Vikash Kumar
  • 395
  • 5
  • 17
  • You can use shared preferences to save toggle current status(true/false) on destroy of acticity 1. And read those preferences when you come to activity again. – Brijesh Kumar Jan 11 '17 at 06:26
  • But if i use Shared preference the value will be remain after killing the application.i want first time all are on that's why i can't use.@brijeshkumar – Vikash Kumar Jan 11 '17 at 06:30
  • If u want first time all ON, set default value true in shared preferences while reading shared preferences. – Brijesh Kumar Jan 11 '17 at 06:36

2 Answers2

1

This is a very general Scenario in Android UI flow: One way could be saving toggle state in Shared preferences as explained here:

You can save the toggle state in onPause() of Activity in Shared preferences and restore the saved values in onResume() of the Activity

Community
  • 1
  • 1
Nargis
  • 4,687
  • 1
  • 28
  • 45
0

you can transfer infomation from activity1 to activity2 by using intent and bundle

-------------------Activity1---------------click

Intent intent = new Intent(this, Activity2.class); 
intent.putExtra("Text", mText); 
intent.putExtra("TextColor", mTextColor); 
intent.putExtra("TextSize", mTextSize); 
intent.putExtra("TextBold", mTextBold); 

startActivity(intent); 

-----------------------------Activity2--------------oncreate

Bundle extras = getIntent().getExtras(); 
mText = extras.getString("Text"); 
mTextColor = extras.getInt("TextColor"); 
mTextSize = extras.getFloat("TextSize"); 
mTextBold = extras.getBoolean("TextBold"); 

in your app, getBoolean is ok

  • i have to get toggle value from activity2 and back to the activity 1 (toolbar arrow button)and then again activity 1 to 2 then i want my last value updated values@fan Yimin – Vikash Kumar Jan 11 '17 at 06:47