简体   繁体   中英

Starting an Activity from a Service

Is it possible to start a Android Activity or App, when a push notification is received using a Service?

This only starts a new Activity, when the App is already running...

This is called in a Service when a push notification is received.

Intent in = new Intent(this, MainActivity.class);
in.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
this.startActivity(in);

Not possible (but possible, see my edit below).

Even if it was possible, do you think it is a good idea that an activity suddenly pops up out of nowhere and replaces anything you were doing? I would surely uninstall this app right away and give it the worst possible rating.

I suggest you show a notification instead.


After thinking about it, it is possible. You can launch any activity using am start -n through the shell, however I strongly discourage you from doing so. The standard method is showing a notification.

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