Search code examples
javaandroidandroid-activitylifecycle

Activities and their lifecycle


Consider this:

  • Activity A
  • Activity B

  • Activity C

Activity A is started when clicking on launcher icon. Activity B is started by activity A - nothing special. But Activity C should be started ONLY by app itself (not on click or something similar ), like broadcast.

THE PROBLEM:

When Activity C is started by app automatically, and when i press HOME button on this activity, and when i click on lanuncher icon (to show up Main Activity - A ), it shows me activity C. If i press BACK button on this activity, then i can go to activity A, with no problem.

How to solve that issue? Killing activity C, on HOME button press, or is some other way to do this?


Solution

  • In manifest of your Activity A put android:launchMode="singleTask" android:clearTaskOnLaunch="true" and in rest of the Activities put android:clearTaskOnLaunch="false", This will solve your problem. Hope this will help you.