从其他app android更改活动

时间:2015-06-02 12:33:25

标签: android android-intent intentservice oncreate

我想阻止某些节目的开放。

示例:我有一个包含所有配置的程序(A)(一个键,要锁定的程序列表)。

当激活(A),并打开一个程序(B)(来自android菜单的短屏)时,如果它在锁定程序列表中,而不是打开它,则应首先打开(A)。我的意图是问我的密钥(A)是否允许,然后打开预定的程序(B)。

示例程序here

提示:app(A)如何查看正在打开的程序(B)并将其替换为我的意图或片段。

P.S。对不起我的英文不好。

1 个答案:

答案 0 :(得分:0)

我用服务

解决了这个问题
    public class RepeatClass extends Service {
        private static final String TAG = "ServiceTag";
        private boolean isRunning  = false;

        @Override
        public void onCreate() {
            Log.i(TAG, "Service onCreate");
            isRunning = true;
        }

        @Override
        public int onStartCommand(Intent intent, int flags, int startId) {

            Log.i(TAG, "Service onStartCommand");

            //Creating new thread for my service
            //Always write your long running tasks in a separate thread, to avoid ANR
            new Thread(new Runnable() {
                @Override
                public void run() {

                    //Your logic that service will perform will be placed here
                    //In this example we are just looping and waits for 1000 milliseconds in each loop.
                    while (true) {try {
                            Thread.sleep(1000);
    //Detect openning programm with activeManager and open normal intent
    }
    catch(Exception e){
    }
}
}
}
相关问题