1

In the app that I am making, there are 12 different activities linked to the main page. All of them are independent of each other. I want the previous activities removed from the back stack so that the app takes less memory. I have managed to have single instance of each activity by using

android:launchMode = "singleInstance"

But still when these activities are started from the main page, 12 different pages go in the back stack and app crashes. What is the work-around?

Phantômaxx
  • 37,901
  • 21
  • 84
  • 115
kirito_y
  • 13
  • 3
  • Try adding Intent.FLAG_ACTIVITY_NO_HISTORY); this flag when you go from one activity another......this thing you can define in manifest as well – santoXme Jun 02 '17 at 07:29

2 Answers2

0

It sounds like android:noHistory="true" would be the solution for you.

A value of "true" means that the activity will not leave a historical trace. It will not remain in the activity stack for the task, so the user will not be able to return to it.

How does android:noHistory="true" work?

Fernando Tan
  • 634
  • 4
  • 14
  • `android:noHistory = "true" ` Doesn't seem to work very well. I mean the memory allocated is still rising for opening activities even. If I switch between two activities a couple of times, the memory keeps on rising (~20MB in each activity call) until the app crashes at 180MB. If there is noHistory of activities in backstack this shouldn't be happening. – kirito_y Jun 06 '17 at 06:20
0

when you go back start the MainActivty,call this on backpress on 12 activitys.

Intent intent  = new Intent(youeActivity.this,MainActivity.class); 
intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK|Intent.FLAG_ACTIVITY_CLEAR_TOP);      
startActivity(intent);
finish();

manofest add this one

android:excludeFromRecents="true"
Jai Khambhayta
  • 4,198
  • 2
  • 22
  • 29