0

I want to directly close the Android Application from any Sub-Activity, and when user can start app again, at that time, app should start in Main Activity , not in Sub-Activity. I used one method: moveTaskToBack(true);

but i can't retrieve successful result.

Help Me.

Thanks.

Net-Android
  • 315
  • 1
  • 3
  • 8
  • System.exit in android app? Seriously? Finish your activity (and all activities that u need closed) by calling activity.finish() when needed. All next fires from this app via launcher will kick start it again a fresh. – Nazgul Aug 23 '14 at 10:01
  • Check : http://stackoverflow.com/questions/18633987/intent-setflags-flag-activity-clear-top/18634598#18634598 – Haresh Chhelana Aug 23 '14 at 10:03
  • Thanks. , I already used System.exit(0) mehtod, but it only finish current activity, not application. – Net-Android Aug 23 '14 at 10:03
  • Check this http://stackoverflow.com/questions/3226495/android-exit-application-code – Jamil Aug 23 '14 at 10:03
  • android.os.Process.killProcess(android.os.Process.myPid()); super.onDestroy(); – Jamil Aug 23 '14 at 10:04
  • Activity.finish(); method is close current activity, not application, I want to stop application from sub-activity. – Net-Android Aug 23 '14 at 10:05
  • Best way is whenever you open Sub-activity with intent use finish it will finish the Previous activity – Rohit Aug 23 '14 at 10:10

2 Answers2

0

you can use Sysetm.exit(0) in on pause method

  @Override
  public void onPause() {

  super.onPause();  // Always call the superclass method first
  System.exit(0);
  }
raj
  • 2,088
  • 14
  • 23
-1

Try this :

if(Build.VERSION.SDK_INT  > Build.VERSION_CODES.GINGERBREAD)
    i.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_CLEAR_TASK);
 else
    i.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP | IntentCompat.FLAG_ACTIVITY_CLEAR_TASK);
startActivity(i);
Mehul Ranpara
  • 4,245
  • 2
  • 26
  • 39