简体   繁体   中英

How to start activity from background service

I have a VoIP application that after it's being swept away from recent apps should show an activity when I receive the call. There is a background service that should create this activity, but after swiping the app away that's not possible.

So, how to start activity from background service in this case?

First of all, you need a UI thread Handler. Just do this in Activity class:

private final Handler h = new Handler();

Then, pass this handler to background service, and do next:

handler.post(new Runnable() {
       public void run() {
         //startActivity
       }

   });

Read about handler here Handler, is such as message queue of thread. You just post message to queue, and it will be processed as soon as possible

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM