Xmarin.Forms Android app restarts onResume on Oreo - android

I have a Xamarin forms Android app that seems to be restarted when the app is brought back to the foreground. (i.e. launch app, tap home button, tap app icon or select app from the recent apps menu.)
This only happens on devices running Oreo and possibly only with the November 2018 patches. I have set the Activity launch mode to LaunchMode.SingleTask and LaunchMode.SingleTop to no avail.
My users authenticate when they launch the app. This is causing them to have to re-authenticate each and every time they navigate away from the app which is not ideal.

Found the answer to this issue on another forum. I had "Do not keep activities" enabled on the device I was using to test. The setting is located under developer options. I had no idea that setting existed.

Related

How to restore a specific activity that is not the launcher activity and instantly navigate to it after the system has killed the app

I have multiple activities in my app and a specific problem in which after my app is killed by the system, upon reopening the app (icon or from the overview) it starts loading my launcher activity with the splash screen instead of loading the last activity that the app was using.
My launcher activity is essentially a form of a login screen which should be used only the first time the app is opened, but instead it is reopened every time the app is killed by the system and app reopened by the user.
I am inexperienced and do not know if this is the default behavior of Android or a bug, I have searched through stack overflow but could not find a conclusive answer.
Coincidentally this well known long standing Android bug has appeared. (https://issuetracker.google.com/issues/36941942)
I do not know if the two problems might coincide, and I cannot be sure when the longstanding bug has first appeared because previously I was testing through Instant Run which does not result in the bug, but am now forced to test through play because it does result in the bug.
Thanks.
I am inexperienced and do not know if this is the default behavior of Android or a bug
This is the default behavior of Android, if there is no current task associated with your app. That includes:
User swiping the task off of the overview screen
You terminating the process and task from inside Android Studio
All the time if the user has been out of the app for 30+ minutes
User using Force Stop on your app in Settings
And probably some other scenarios that I'm not thinking of right now
My launcher activity is essentially a form of a login screen which should be used only the first time the app is opened
I recommend that your launcher <intent-filter> be on your primary activity in the app. If that activity determines that the user has not logged in, it can do something to authenticate the user (display a fragment, start an activity, etc.).

Not getting push notification when swipe from recent

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.

Android keep my launcher as default

I am developing an android app for a company. Their employees must not use any other apps but the company-app,the preinstalled phone-app to make calls and the settings.
So I created a custom launcher and registered it as default. The launcher shows only the allowed apps. But the employees could open the settings and set the normal android launcher as default (and then use the internet for doing unallowed things or download malware) or uninstall my launcher.
Is there any possibility to prevent this without rooting? If I register the laucher as device administrator they could open the settings and disabling it.
Note: I have full access to the devices before they were delivered.
Best regards
I found a solution
1. I registered my app as boot-receiver
2. I created a service which tests which activity is in foreground (if it is from the whitelist: OK, otherwise: my app comes to foreground, blocks the foreground-activity and shows the user a warning "don't do this")
The next problem was: the user should be able to use the settings (for wifi), so he could uninstall my app.
3. Register my app as device admin (the user is unable to uninstall or force-stop my app until he unregister it as device-admin)
While testing which activity is in foreground, the service tests if the app is still device-admin. If it isn't device-admin, all apps were blocked until the app is device-admin again (the dialog pops up).

How to prevent app restart when using launcher after store?

My Android application is being restarted when using the launcher to launch it after I have used the app store to launch it (and visa versa). Is there any way to prevent this?
By restarted I mean that the activity stack is lost. This is important as our users are setting up and returning to an activity in the app intermittently over the course of an hour or so. After first install, they will likely have installed and opened the app from the app store, set themselves up and then backgrounded the app. Later they are likely to open the app from the launcher and lose all their state!
The problem is further compounded as we start a foreground service along with the set-up activity. Clicking the services notification should bring the user back to the set-up activity but, as with the launcher, if the user originally opened the app from the Play store, they again lose all their state!
Reproducing the problem
I've made a sample application here:
https://github.com/samskiter/LaunchTest
Note: it uses the BBC weather application package Id in order to allow you to quickly open from the app store (the "Open" button will be shown on the BBC weather application if this app is installed).
Steps are as follows:
Uninstall the BBC weather app if you have it
Install the LaunchTest app
Close the LaunchTest app from recents
Open the LaunchTest app from the BBC weather app page on the Play Store
Click the button to navigate to the Second activity
Background the application (press home)
Open the LaunchTest application from the app launcher
The state is lost! you are back at the First (root) activity
What I've tried
Using singleTask launch mode hasn't helped - it causes the app to be relaunched even if you use the launcher every time.
I've tried alwaysRetainTaskState - I don't really expect this to work as this only really affects things over about a 30 minute wait.
What I think is going on
There is no mechanism in the activity manager / intent system to open a running app in it's current state. Instead, I think the UID of the launching application is taken into account. If it is different then the Intent.FLAG_ACTIVITY_NEW_TASK flag is forced and so created a new task and dropping all my users' lovely state.
Inspecting Google Maps
Google maps has a very similar interaction model to our application: a setup UI, followed by an ongoing process the user is going through for a long period of time (navigation) with a paired, foreground service (the navigation service you can see in your notification bar). BUT GMaps doesn't suffer from this problem. I think this is because it uses only a single activity for all of it's interface and uses singleTask. So now, when you tap on the launcher after originally launching from the play store, the task can be reused.
In my opinion this exposes a hole in the android intent/activity management system. The whole point of the savedInstanceState/activity lifecycle is to prevent dropping state, but here we have a way to dump everything. My current best solution is to detect app restarts by the fact the service is running and try to get the user back to where they were, which is more than a little tricky.
If someone knows a way I can prevent my state being dropped on the floor when reopening from the app launcher after opening from the store, I would really appreciate it.
This is more like a workaround to your problem, but it seems that there may be no real solution.
My first thought was - since the whole setup will take a while anyway - why don't you just save some kind of bookmark ('firstLaunch') to Preferences, post a (delayed?) notification and finish the app, so that the user has to open it again by tapping on the launcher icon. Only then you start the real setup, so you will not lose information due to the installer vs launcher problem.
But the problem seems to have been around for some time and the following SO-posts may help:
Re-launch of Activity on Home button, but…only the first time
After tap on app icon,launcher create a new instance of root activity again & again
Hope this helps!

Flex 4.5 - Android application keeps running in background, How can I shut it down?

I am building an Android application in Flex 4.5 and I am testing on a Samsung Galaxy S phone.
My application uses GPS and also Google maps.
When I run the application, and I try to close it, the application keeps on running in the background. I would like the application to stop when the user presses the device's home button or when the user clicks the back button until they leave the application.
How can I make the application shut down in both the cases?
This is how Android applications are supposed to work. See here: http://developer.android.com/guide/topics/fundamentals/processes-and-threads.html
Your application's process is in either the "background" state (if the user pressed how) or "empty" state (if the user pressed back).
For starters, you can try using the Activity noHistory flag in the manifest. This will make sure an Activity is finished if navigated away from.
http://developer.android.com/guide/topics/manifest/activity-element.html#nohist

Categories

Resources