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 ?
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.
Related
I am trying to make app that implements service for running apps (eg. yt, chrome, google maps) and measuring internet connection and how much data is downloaded.
So the idea is to start activities and run applications metioned above in patterns, eg.
Run some YT video for 5 mins.
Load 10 articles in Chrome one after another.
...
And every one min internet connection statistics are gathered.
The issue is that when I do
Intent intent = new Intent(Intent.ACTION_VIEW);
intent .addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
startActivity(intent);
inside service the startActivity works only once, every other time debug console shows:
I/Timeline: Timeline: Activity_launch_request time:29210990 and no avtivity is started.
I have tried bunch of different flags on intent:
intent.addFlags(Intent.FLAG_ACTIVITY_NO_HISTORY);
intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
intent.addFlags(Intent.FLAG_ACTIVITY_SINGLE_TOP);
intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TASK);
intent.addFlags(Intent.FLAG_ACTIVITY_MULTIPLE_TASK);
Not sure how it's suppose to be done, thanks for any help :)
Hi Developers I hope All are You fine. I need help. I make a AppLocker app and I use service to check which app i currently running. i locked app in my database with package name. When I show my lock screen From Service my Intent hit but lockScreen not Showing.How i call Activity From Service below is my Codeto start Activty from Service
if (locker_list!=null) {
if (launchapp) {
Log.d("TAG", "run: lock Screen Show");
Intent intent = new Intent(mContext, Lock_app_screen.class);
intent.putExtra("package_name", current_app);
intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
mContext.startActivity(intent);
}
}
Android 10 (API level 29) and higher place restrictions on when apps can start activities when the app is running in the background. These restrictions help minimize interruptions for the user and keep the user more in control of what's shown on their screen.
for more...
see this
I have found this post how to make an application to start after Android OS boot is completed. I have done it good - I am catching the broadcast android.intent.action.BOOT_COMPLETED, but unfortunately my app crashes and I cannot observe it with logcat because I have to reboot the device in order to see if my feature is working.
Does anybody know how can I catch an exception so I can see why my app is crashing OR does anybody know what could be the problem (if you have experienced the same problem)?
I have solved the problem... The initial intent was:
Intent i = new Intent();
i.setClassName("com.example.app", "MainActivity");
i.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
I made a toast with exception in it and made printscreen on emulator.
The exception said this:
android.content.ActivityNotFoundException: Unable to find explicit activity class{com.example.app/com.example.app.MainActivity}; have you declared this activity in your AndroidManifest.xml?
After checking, my activity was in the file. So I googled this
and made correction in my intent to:
Intent i = new Intent();
i.setClassName(context.getPackageName(), "com.example.app.sunshine.MainActivity");
i.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
and context.startActivity(i); started the app after reboot.
How can I open Running services settings?
Is it possible to open this page using Intent or Method invoke?
Running services
This only works on 5.1 and below.
Intent intent = new Intent();
intent.setComponent(new ComponentName("com.android.settings", "com.android.settings.RunningServices"));
startActivity(intent);
Somehow on 6.0 this call opens the configure apps page showing title running services. May be there are some extra flags that need to be passed.
In my app I want to launch apps(messaging,contacts,etc)if my launched app(messaging,contacts,etc) is already running in background I want it to bring front.I tried using moveTaskToFront() but it doesn't implement from above API 23(Lollipop).So,I ended up with this code:
Intent intent=getPackageManager().getLaunchIntentForPackage("com.android.mms");
intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
startActivity(intent);
By using this code if I launch a messaging from inside my app it launches,and if I again launches the same app from inside my app it perfectly resumes it and continue from where we left it.
But when I Launches the same messaging app from my default android launcher it just create new instance of messaging app on above of my already running messaging app which was already launched by my app.
I don't know what the solution for this.Please help me ...
Use the below approach to invoke intents within your app like this.
Intent intent = new Intent(CONTEXT, TARGET_ACTIVITY.CLASS);
intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP | Intent.FLAG_ACTIVITY_SINGLE_TOP | Intent.FLAG_ACTIVITY_NEW_TASK);
startActivity(intent);