keeping the state of the previous activity


keeping the state of the previous activity



If I am working on Activity A and I want to start Activity B, I do the following to start Activity B:


Intent detailsIntent = new Intent(ActivityA.this, ActivityB.class);
detailsIntent.putExtra(EXTRA_MESSAGE, value);
startActivity(detailsIntent);



When I press the back button on Activity B, a new Activity A will be created and my old state is gone. I don't want to use savedInstanceState to restore some variables but I want the first Activity A to come back in the exact same state I left it in.


savedInstanceState



EDIT:
The relevant AndroidManifest.xml


<activity
android:name=".ActivityA"
android:label="@string/app_name">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity
android:name=".ActivityB"
android:parentActivityName=".ActivityA" />





I don't want to use savedInstanceState to restore some variables but I want the first Activity A to come back in the exact same state I left it in. ... then you should change target platform ... savedInstanceState (or persistent storage) is the way to do this on android OS
– Selvin
Jul 2 at 9:37






When I press the back button on Activity B, a new Activity A will be created How? Please post your Manifest as the default behaviour is that Activity A is put in the backstack when the Activity B is launched, and its state is automatically restored when you press back on Activity B.
– Eselfar
Jul 2 at 9:40



When I press the back button on Activity B, a new Activity A will be created





Activity A will be kept in memory for a period of time except you manually call finish on it, so your problem needs more information to find out. But for memory and performance concern, Android can swipe Activity A at any time if your app consumes too much memory, or your app goes to the background for too long. And for this reason, savedInstanceState is there to ensure your app won't crash. You have to learn to use it sooner or later.
– Tam Huynh
Jul 2 at 9:50


finish


savedInstanceState





might be you have written some code in onResume() of Activity A.. if yes, please move that to onCreate of Activity A
– Manoj Bhadane
Jul 2 at 10:17









By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

Popular posts from this blog

api-platform.com Unable to generate an IRI for the item of type

How to set up datasource with Spring for HikariCP?

Display dokan vendor name on Woocommerce single product pages