Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is it possible to detect exit of an application?

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 message and go back to my activity (from where each application launch) using running tasks. My application act as a home launcher.So intent to this activity if the is a blocked application.For eg: It is possible to launch Camera from Gallery in Samsung device.If the camera is not an allowed one shows blocked message and exited to my acivity.But when relaunching Gallery the blocked message shows again beause the top activity(Camera activity) lied in the stack.

But the exiting of these blocked application did not work perfectly.

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

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

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

Thanks in Advance

like image 471
Devu Soman Avatar asked Apr 30 '13 11:04

Devu Soman


1 Answers

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

like image 60
Triode Avatar answered Sep 27 '22 23:09

Triode