安卓:杀应用程序中的所有进程 [英] Android: Kill all processes in an application

查看:130
本文介绍了安卓:杀应用程序中的所有进程的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在我的应用程序有一个应用程序和一些活动。我想干掉后,在特定的时间我的应用程序(例如,3分钟)用户$ P $后pssed主页按钮。我能够完成的应用程序S的过程,但只要我的活动还活着,他们试图从他们的最后状态启动。

In my application I have an "Application" and several Activities. I would like to kill my application after a specific time (ex. 3 minutes) after user pressed the Home button. I'm able to finish the "Application"s process but as long as my activities are alive, they tries to start from their last state.

Thread isOnDisplayThread = new Thread(new Runnable() {



            @Override
            public void run() {
                Timer mTimer = new Timer();

                mTimer.schedule(new TimerTask() {

                    @Override
                    public void run() {
                        Log.d(TAG, (isApplicationOnDisplay) ? "Application on display" : "APPLICATION ON BACKGROUND");

                        if (!isApplicationOnDisplay) {
                            notOnDisplayTime++;
                            if (notOnDisplayTime >= 10) {

                                Process.killProcess(Process.myPid());
                            }
                        } else {
                            notOnDisplayTime = 0;
                        }

                    }
                }, 0, 1000);

            }
        });

        isOnDisplayThread.run();

P.S。 isApplicationOnDisplay 是一个静态布尔由每一项活动的的onPause() onResume()的方法。

P.S. isApplicationOnDisplay is a static boolean controlled by every Activity's onPause() and onResume() methods.

有没有什么办法去杀死一个应用程序的所有相关活动?

Is there any way to kill all related activities of an application?

推荐答案

(我不明白为什么每个人都试图杀死自己的应用程序...)

(I can't understand why everybody tries to kill his own application...)

杀死一个应用程序应该的永远的是由应用程序完成的(虽然有时一个任务管理器都有自己的优势)。

Killing an application should never be done by an application (though sometimes an task manager has his advantages).

我能够完成的应用程序S的过程,但只要我的活动还活着,他们试图从他们的最后状态启动。

I'm able to finish the "Application"s process but as long as my activities are alive, they tries to start from their last state.

您有关于状态处理完全控制,你决定,如果一个活动继续最近的状态还是不行。如果你不希望目前的行为,改变它,但不要试图杀死你的应用程序。

You have full control about the state handling, you decide if an activity continue with the latest state or not. If you don't want the current behavior, change it, but don't try to kill your application.

要长话短说: Android操作系统决定如果一个应用程序应该杀/停止或不

这就是如何机器人的设计和应该如何使用?

Thats how android is designed and how it should be used...

这篇关于安卓:杀应用程序中的所有进程的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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