Is it possible to detect exit of an application?

前端 未结 1 1563
北恋
北恋 2021-01-11 17:26

My android application allows to launch other installed applications from this.This shows some allowed apps. If the user try to launch a disallowed application then show a m

相关标签:
1条回答
  • 2021-01-11 17:53

    Is it possible to get close/exit event of an application?

    Yes it is possible inside your LauncherActivity You can override onDestroy this method will be called on application exit.

    How can i finish an application as whole(By finishing all its applications)?
    

    I believe you want to stop your all running activities here. This can be achieved in multiple ways.

    android.os.Process.killProcess(android.os.Process.myPid());
    

    or

    Intent intent = new Intent(getApplicationContext(), YourHomeActivity.class);
    intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
    startActivity(intent);
    

    This will clear all the activities and will brings the user to the HomeActivity. While calling this you can add a flag in intent and using that value you can finish the HomeActivity also. Use finish() method to finish the activity.

    How to launch an application without having any history of previous launch?

    You can use the same above Solution to achieve this. The second one.

    Hope this will help.

    There is an onTerminate method in application class, but this cannot be used in production environment. See more about this here

    0 讨论(0)
提交回复
热议问题