Issue
I keep losing data when pressing the back button after going back from activity 2 to 1.
when passing the data to activity 2 I'm using
intent = new Intent(getApplicationContext(), secondactivity.class);
startActivity(intent);
to launch the second activity. is it possible not to lose the data without using sharedpreference when pressing the back button?
Solution
You can store your data in the Application class and use it everywhere
Create a class:
public class MyCustomApplication extends Application {
String myData = "";
}
in manifest add class name as android:name
<application
android:name=".MyCustomApplication"
android:icon="@drawable/icon"
android:label="@string/app_name"
...>
access it like this from any activity
String myData = ((MyCustomApplication)getApplication()).myData;
((MyCustomApplication)getApplication()).myData = "new value";
Answered By - merwan ezio
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.