Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to start activity from service in Android10

I was starting activity from services till android P, but from android10 google has kept one restriction that activity cannot be started from background.

https://developer.android.com/guide/components/activities/background-starts

// below code stopped working
Intent intent = new Intent(this, MyActivity.class);
intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
startActivity(intent);

what should i do for android10 ?

like image 733
Rahul Avatar asked Sep 18 '19 09:09

Rahul


People also ask

How we can start activity and service in Android?

Start a service. An Android component (service, receiver, activity) can trigger the execution of a service via the startService(intent) method. // use this to start and trigger a service Intent i= new Intent(context, MyService. class); // potentially add data to the intent i.


1 Answers

You can use a notification using setFullScreenIntent, it's the best you can do or you can ask for SYSTEM_ALERT_WINDOW permission but it doesn't work with android go devices.

like image 179
greywolf82 Avatar answered Sep 18 '22 07:09

greywolf82