是有可能检测到应用的出口? [英] Is it possible to detect exit of an application?

查看:103
本文介绍了是有可能检测到应用的出口?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的Andr​​oid应用程序允许启动其他安装的应用程序从this.This显示了一些允许的应用程序。如果用户试图启动一个应用程序不允许然后显示一个消息,并回到我的活动(从每个应用程序的启动)使用正在运行的任务。我的应用程序的行为作为家庭launcher.So意图这项活动,如果是阻塞application.For例如:它可以从画廊推出相机在三星device.If相机是不是允许一所示封锁消息,并退出我的acivity.But重新推出画廊,当被阻止消息再次显示beause在顶(摄像头活动)在堆栈中撒了谎。

但这些拦截的应用程序的退出并没有很好地工作。

  1. 是否有可能亲近一个应用程序/退出事件?

  2. 我要如何完成一个应用程序作为一个整体(通过完成它的所有应用程序)。

  3. 如何启动一个应用程序,而不必previous推出的任何历史?

在此先感谢

解决方案
  

是否有可能亲近一个应用程序/退出事件?

是的,它有可能在你的 LauncherActivity 您可以覆盖 的onDestroy 此方法会被调用的应用程序退出。

 如何完成一个应用程序作为一个整体(通过完成其所有的应用程序)?
 

我相信你想在这里停止你所有正在运行的活动。这可以以多种方式实现。

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

 意向意图=新的意图(getApplicationContext(),YourHomeActivity.class);
intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
startActivity(意向);
 

这将清除所有的活动,并带来了用户对 HomeActivity 。当调用这个你可以在意图上增加一个标志,并使用该值可以完成 HomeActivity 也。使用完成()的方法来完成的活动。

  

如何启动一个应用程序,而无需对previous任何历史   启动?

您可以使用相同的上述解决方案来实现这一点。第二个

希望这会有所帮助。

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

解决方案

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.

这篇关于是有可能检测到应用的出口?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆