Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Go back to the First/Main activity without reloading it

I am developing an android app. I need to call my MainActivity without reloading it as it has huge amount of data fetch from internet.

Suppose, I am on third activity now and I want to go back 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 don't want to reload it. like from Second Activity I call finish() and it does exactly want i need.

like image 533
Sarim Sidd Avatar asked Apr 06 '12 10:04

Sarim Sidd


People also ask

How do you return data to the starting activity?

Use startActivityforResult to start Activity B. Implement override onActivityResult(int, int, Intent) method in Activity A and setResult in ActivityB. Use startActivityforResult in Activity A to launch activity B and use @override onActivityResult(int, int, Intent) method in your activity A to get data from B Activity.

How do I find my main activity?

This can be found in the application's manifest. The main activity is the activity with the intent-filter whose name is android. intent. action.

Which method is used to start another activity?

To start an activity, call startActivity() and pass it your Intent . The system receives this call and starts an instance of the Activity specified by the Intent .


2 Answers

This is 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);
like image 180
Eng.Fouad Avatar answered Nov 14 '22 20:11

Eng.Fouad


metntion it in your AndroidManifest.xml file

<activity android:name=".MyActivity"

              android:configChanges="keyboardHidden|orientation">

do nothing inside the method onResume() and onstart() when coming back to this activity

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

like image 40
Ravi1187342 Avatar answered Nov 14 '22 22:11

Ravi1187342