سؤال

I'm developing Android application where I'm switching between activities.

But I grasp several problems:

  • If I'm starting new Activity then clicking on the "back" button in my smartphone I'm returning to the pervious activity. But what if I want to make my application be closed by clicking on that "back" button from the new activities and not returning to the pervious? Is it possible to terminate my application from the new activities by the way I'm asking you?

  • As I understand all activities which were created by the method StartActivity() are holding at the RAM memory of my device. I also don't want to hold all them in the memory space. How can I set some activities not to hold in memory and make them free from the memory space, and what is the best solution for keeping required activities moves (for the history) and for the deleting from memory space the old activity?

هل كانت مفيدة؟

المحلول

The simplest way, as I understand your question, is just to call finish() on those Activities which you don't want to keep. This will destroy them, removing them from the stack and from memory.

However, I wouldn't worry so much about memory here as I would worry about your user's experiences. Don't remove these Activties simply for the purpose of conserving memory. Do it because they aren't needed and when the user presses the "Back" button they don't expect to see them.

مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى StackOverflow
scroll top