Return to the first / main activity without rebooting

I am developing an Android application. I need to call MainActivity without restarting it, since it has a huge amount of data from the Internet.

Suppose now I am engaged in a third activity and I want to return to MainActivity.

If I use:

Intent i = new Intent(Third.this,Main.class); i.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP); startActivity(i); 

it will load MainActivity, but I do not want to restart it. as from the second action, I call finish() , and he definitely wants what I need.

+6
source share
4 answers

report it in the AndroidManifest.xml file

 <activity android:name=".MyActivity" android:configChanges="keyboardHidden|orientation"> 

do nothing inside the onResume() and onstart() when returning to this activity

and try intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP); instead of the addFlags() method

+4
source

Here's how to do it:

 Intent i = new Intent(this, MainActivity.class); i.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP | Intent.FLAG_ACTIVITY_SINGLE_TOP); startActivity(i); 
+7
source

In the third action, when you want to go to the first action, put the final () mw there.

In Second activity, after the onCreate () method, put @Override public void onResume () {super.onResume (); The end(); }

I think this code will work for you, jus try it.

0
source

Try adding this to your manifest:

  android:configChanges="keyboard|keyboardHidden|orientation"> 

add this line to the action in your manifest as follows:

  <activity android:name=".Main" android:label="@string/app_name" android:configChanges="keyboard|keyboardHidden|orientation"> <intent-filter> <action android:name="android.intent.action.MAIN" /> <category android:name="android.intent.category.LAUNCHER" /> </intent-filter> </activity> 
0
source

Source: https://habr.com/ru/post/912585/


All Articles