Reputation: 465
For several months I am creating an application for Android and I have a problem I can not solve : my application unexpectedly crashes after a few minutes of use. Thanks to the " Memory Monitor " of Android Studio, I can see that my application is using more and more memory over time : when I change activity , memory usage increases but not decreases, which then causes the stoppage my application when any memory allocated to it is used (256 MB) .
Do you have a solution to ensure that the memory used ceases to steadily increase over time as if already vacated activities continued to use memory ?
Here is a screenshot of Memory Monitor , phases rising with red arrows correspond to the launch of various activities. The blue arrow indicates when the application leaves unexpectedly.
Upvotes: 1
Views: 3073
Reputation: 8916
When starting your new Activity, set its Intent flags like so:
Intent intent = new Intent(...);
intent .setFlags(intent .getFlags() | Intent.FLAG_ACTIVITY_NO_HISTORY);
startActivity(i);
or add android:noHistory="true"
to the setting of your activity in manifest.
This way force an activity to be added to the history stack.
Also you can clean up your memory in onDestory
take a look at this link :
android-cleaning-up-memory-on-app-destroy
Upvotes: 2