0

I have a few specific Questions.

I´m developing a touristic app. It works great, but after a long time launching new activities it crashes. I used the debug and i realized it uses a lot of memory, it is like the activities don´t closes altought I call.

@Override
public void onBackPressed() {
    super.onBackPressed();
    this.finish();
}

after removing some static variables and using in every new activity this flag

Intent.FLAG_ACTIVITY_CLEAR_TOP 

memory space is relieved. App performance looks good, altought it uses a lot of images and listviews because i used Holders

However, in the main activity i placed the same onBackPressed code, but after pressing it the app is not closed, the memory usage is decreased but i have my doubts

Here is my Questions

  1. Is the app really closing?

  2. It still there because is a recent app?

  3. The memory usage decreasing means that the activity FLAG_ACTIVITY_CLEAR_TOP and onBackPressed() is Working?

  4. Is this the right way to manage the activities to finish() ?

UrielUVD
  • 482
  • 1
  • 9
  • 27
  • See this if it helps you http://stackoverflow.com/questions/20469023/android-outofmemory-error-and-the-backstack/20680484#20680484 – Kanwaljit Singh Apr 10 '14 at 10:36

1 Answers1

0
  • http://developer.android.com/training/articles/memory.html Check this out it may help you with the memory issue.
  • Secondly, if your app makes use of internet connection, do check out your code for checking the internet connection to be present or not.
  • Thirdly, it seems that you have written all the code in the onCreate() method, hence the app is taking a long time. Make use of AsyncTask.
  • Fourthly, whenever you call finish() method, the app closes. So it is the right way.
void Adi
  • 318
  • 1
  • 4
  • 12
  • I use Asynctask, but i call it from onCreate(), Is better to call it in onStart() ? or onResume()? Thank you. – UrielUVD Apr 10 '14 at 17:52
  • After onBackpressed in the first activity the monitor still shows the aplication using memory, it seems like the app is not finished – UrielUVD Apr 10 '14 at 18:39
  • No, you should call it from onCreate() itself and not onStart() or onResume(). The onCreate() is the main thread on which all the activites run. – void Adi Apr 11 '14 at 09:15
  • http://stackoverflow.com/questions/4342761/how-do-you-use-intent-flag-activity-clear-top-to-clear-the-activity-stack maybe this link could help you. – void Adi Apr 11 '14 at 09:22
  • Ok. Just added my AsyncTasks to the onCreate() method. @void Adi , i read the article, as I understand the onBackPressed() will clear the top of activities stack and make a new intent of a previous activity as a new activity, it works good, but in my situation this is not proper, the previous activity have downloaded a lot of images in a listview and make a new activity of it will mean use a new internet connection and download the images again. Because of that i prefer not re-Create an activity that is the same as one I have already created. Thank you all for your comments :D – UrielUVD Apr 11 '14 at 20:11