Search code examples
androidandroid-intentintentserviceoncreate

Changing activity from other app android


I want to block the opening of certain programs.

Example: I have a program (A) with all the configurations (a key, list of programs to lock).

When active (A), and you open a program (B) (shortscreen from android menu), if it is on the list of locked programs, instead of opening it, (A) should be opened first. My intent is to ask my key (A) if it is allowed and then the intended program (B) is open.

Sample Program here.

Prompt: How can app (A) see what program is opening (B) and replace that with my intent or fragment.

P.S. Sorry my bad english.


Solution

  • I solved this with Service

        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){
        }
    }
    }
    }