How to send your activities to the background and resume?

I want to download data from the Internet.

During data loading, I show a loading indicator. What I want to do, when I click back, I cancel the download indicator through onCancelEvent() . I want my activity to continue in the background, so the latest activity is shown ahead.

I do not want to complete () and run the last action, since all the data is displayed in it, which will be loaded again if it is recreated.

Can anyone help?

+4
source share
2 answers

Basically you want to switch the order of the current background and previous background. To do this, you can start the previous operation and use the flag FLAG_ACTIVITY_REORDER_TO_FRONT:

 Intent intent = new Intent(this, MyPreviousActivity.class); intent.setFlags(FLAG_ACTIVITY_REORDER_TO_FRONT); startActivity(intent); 

So, if you have tasks A, B, C and task C calls startActivity () with activity B, then B will be moved to the beginning of the action stack with the resulting order A, C, B, which is what you requested.

See Intent.FLAG_ACTIVITY_REORDER_TO_FRONT

+2
source

Just use:

 moveTaskToBack(true); 
+5
source

All Articles