In fact, I know that I'm asking about a simple and basic Android concept. But I'm a little confused about these finish() and onDestroy() methods. Will it kill activity and free up resources associated with these actions?
I tried with a simple application that contains only one action. I thought the concept was similar. When the application starts, the action will begin. and when we press the back button, it will finish. And I gave some toast message in each life cycle to find out about memory usage. And when I clicked the back button, it did onPause() , onStop() and onDestroy() . I thought this activity was over. But when I resumed the application again, then it took up more memory than in the previous time. This happens every time I launch the application from eclipse or restart the application from the main screen.
Why is this happening? How can I actually destroy an application / activity to free up memory?
I am including the code. I just give only one toast message inside the class. Then increases memory usage.
Every time I run the application, the allocated size increases as: 3302744, 3442384, 3474552
public class myActivity extends Activity { @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); Toast.makeText(getBaseContext()," allocated size = " + Debug.getNativeHeapAllocatedSize(), 1).show(); } }
manifest:
<application android:icon="@drawable/icon" android:label="@string/app_name"> <activity android:name=".myActivity " android:label="@string/app_name" > <intent-filter> <action android:name="android.intent.action.MAIN" /> <category android:name="android.intent.category.LAUNCHER" /> </intent-filter> </activity> </application>
Why is memory increasing every time?
Jomia source share