I'm not getting notification when user swipe the app from recent. I've notice that behavior occurs in some specific device for instance I've tested it on nexus devices and HTC devices it's working fine but when user swipe the app from the recent in huawei and some samsung devices it doesn't show notification. I mean i don't get onMessageReceived() callback
After some research I found out that in these devices when user swipe it from recent it force stop the app (the process is completely killed) and I don't get any notification. In huawei they have protected and unprotected apps and if I add the app in protected list from the setting, I start getting notification because i this case it doesn't force stop the app. and I believe in samsung they have the same thing with blacklist and whitelist apps.
I've also tried some solutions like restart the service onTaskRemoved() callbacks or make your app START_STICKY. I've also tried WakefulBroadcastReceiver but nothing is working for me.
So my question is how can i get notification even if it gets forced stop, like it's happening when swiping app from recent.
An old question, but I think it’s important to know that HUAWEI has a feature called “power-intensive app monitor “. It kills every app that runs in the background for a long time unless user gives special permissions to it.
The path to do this:
Settings -> Security & privacy -> Location services -> recent location requests: YOUR APP NAME -> Battery -> uncheck Power-intensive prompt, App launch: Manage manually: check all three positions: Auto-launch, secondary launch, run in background.
I don’t know if there's a way to do this programmatically. I think the best way is to create a sort of help activity and explain the user what to do if application won’t work.
Related
I have a App that i now wanted to expand with Silent Push Functionality for a customers Feature Request.
But now i encounter a rather strange behaviour(app freeze)
The Used Xamarin.Forms Version is 4.8.0.1451 (Updates did not solve the problem)
The Problem is Android Only related
Normal Notifications work as expected and dont produce any error
Here the quick Behaviour:
Receiving Silent Pushes works if the app is in Foreground (Multible times no limit)
Bringing the App to the Background and back to Foreground works also flawles
Do i Receive a Silent Push while the App is in Background or the Device is Locked and i bring back the App to Foreground/Unlock the device the app seems frozen (unresponsive and App.OnResume does not get executed)
(Also to note: i can only receive 1 silent push when the app is in Background/Device is locked)
For now i dont do anything on receiving the Silen push (to isolate this error)
Debug output aswell as LogCat does not provide any info what so ever.
i could not track any managed code that does execute and not return properly from some method calls
i can reproduce this problem on android 11(Pixel3) and android 9(Blackview A60)
I hope someone here has an idea what this problem could be.
It more informations or details are needed, i happily provide
In Android, starting in Android 8.0 (API level 26), an Android application no longer have the ability to run freely in the background.
When in the foreground, an app can start and run services without
restriction. When an application moves into the background, Android
will grant the app a certain amount of time to start and use services.
Once that time has elapsed, the app can no longer start any services
and any services that were started will be terminated. At this point
it is not possible for the app to perform any work.
For more details about this, you can refer to Background Execution Limits in Android 8.0.
Here is the thing, I am not used to the latest android yet and the new system is giving me some confusions. Usually, for the older androids, if I close all background apps, I won't get new notifications from them. But after switching to a new phone with the latest android, I realized that even if I do close all background apps, I still keep getting notifications from them. So, how are the apps still pushing notifications if I already close them from background?
(Say google maps for example, I am 100% sure I killed it in background but now it keeps notifies me about my live traffic status on my notification bar.)
So Here's the answer-
Yes, they are. Whenever the Internet is turned on or you get a message, listener of that app wakes up and check for any notification and if there is something new, it shows you the notification.
These apps keep running in the background if not put in sleep mode by your phone and use the resources.
Like you don't want to get notified by WhatsApp for a new message but the moment you change the network, unlock your phone again or turn the data on, an event listener will wake up and notify you of new messages.
Also, wake timers are used to notify you after some fixed time like after every 5 minutes.
This is the thing I hate the most.
Not promoting but here's the app - search play store for Shutapp - Real battery saver (Blocked from Play store a while ago and doesn't work anymore for "obvious" reasons). It will turn off all the background apps and you'll be amazed to see a long list on first use.
This will remove all the apps from background until you open them again. I use this app most of the time and it really works great.
Try this out.
I've been using onTaskRemoved() method in a Service to detect when an app was removed from device RECENT list by swiping it away. I preform some logging and some other operations that need to take place when this happens.
It works perfectly.
Then I checked this method in an HUAWEI device running Android 6.0.
The method never gets called. I also added a Log.d call and as expected, this log never appeared. The same happens on a XIAOMI device.
Any ideas why this happens and how to resolve this? Or is there another way to detect app was removed from RECENT list with out relying on onTaskRemoved() ?
Thanks
On some devices (some LG, Huawei, Xiaomi, and others) your app needs to be manually added to a list of "protected apps" or "apps that are allowed to run in the background" in order for Android to restart STICKY services. If your app has not been manually added to this list, Android just kills your processes and does not restart them and also does not call onTaskRemoved(). This is done to preserve battery life by limiting the number of apps that can have STICKY services running in the background.
On such devices you should see a page in the "Settings", sometimes under "power management", sometimes other places, where you need to explicitly add your application. You'll also need to tell your users to explicitly add your app to this list.
When user has installed your app on xiaomi device, redirect user to auto start activity and tell user to switch on:
if (Build.BRAND.equalsIgnoreCase("xiaomi")) {
Intent intent = new Intent();
intent.setComponent(new ComponentName("com.miui.securitycenter", "com.miui.permcenter.autostart.AutoStartManagementActivity"));
startActivity(intent);
}
Use the above code to launch autostart activity page on xiaomi
I've been using onTaskRemoved() method in a Service to detect when an app was removed from device RECENT list by swiping it away.
With giving more light to the answer provided by David Wasser
It doesn't new on Xiaomi because Xiaomi has a feature called app permission, where a user has to allow the app to start automatically (Service). In your case the Service is not called, once its terminated from stack.
Go like this and allow your app to autostart:
Settings > permissions > Autostart
In My Huawei also i was facing porblem, Just go Setting => Power Saving => Protect App => find your app and enable it.. Service will start running..
My goal is to make my app unkillable.
Application has admin permissions granted.
I have one activity and one service.
Applionation cannot be uninstalled while Admin permission is active (thats good).
Service is auto re-creating. That's also correct.
Unfortunately on Android 5 - Lollipop user can click on all apps button - then go to Task Manager and simply END my app without any problems. After that service is destroyed for good (activity too obviously...)
Is this a way to prevent that?
1) Xposed. At the cost of execution speed and dependency on the TaskManager that you will have to reverse-engineer a bit...
2) USER_PRESENT and friends. Your application can register a BroadcastReceiver and re-start on events. That is, it will be killable, but it will restart.
I think you are interested in something like a kiosk mode: displaying a single app and preventing to break out from it.
There are various tutorials out there. This one is quite good:
http://www.andreas-schrade.de/2015/02/16/android-tutorial-how-to-create-a-kiosk-mode-in-android/
Edit: if your main target are Android 5.0+ devices you can also make use of screen pinning. http://developer.android.com/about/versions/android-5.0.html#Enterprise
Just update to Android 5.0 by OTA. The biggest find is that if a user Force Stop my app(in System Setting), my app stops right now. And my app cannot receive any broadcast anymore, even if my receiver is registered in AndroidManifest.xml. More surprisingly, when the user reboot the device, my app even cannot receive android.permission.RECEIVE_BOOT_COMPLETED broadcast.
Does anyone pay attention to this?
Yes, I just noticed that on my Nexus 5, and I'm really loving it!
When the user "Force Stop" an app in Settings->Apps, it will be TOTALLY stopped and is black listed from receiving any broadcasts UNTIL the user open the app from the launcher.
I see it as a way like the "Disable" of system apps, you completely disable this app until you open it again.
I see this really very useful as I have lots of apps that are using unnecessary services in the background like Facebook for instance.