Why does updating an app clear its defaults? - android

Let's say you have an app that declares itself able to handle a system intent like Phone and that the user selects it as the default app. When the market updates the app, why does it clear the defaults? Is there a way to prevent that, so if I wanted Dialer 1.0 to handle the phone button, Dialer 2.0 will still do it without me having to re-select it.

The defaults map to specific implementations in the application (the name of the class implementing an activity), which can change when an application is updated. To be conservative and safe, the platform has traditionally cleared those when an application is updated because they may change and result in a reference to an activity that no longer exists. There is nothing you can do in your app to prevent this from happening.

Related

Flutter - Do not restart application when restoring

Friends,
does anyone know how to prevent the application from restarting when restoring it? For example, the application is minimized, then restored and it restarts, any way to avoid it?
This is platform dependent, per example in android it depends on the ram available, if the device needs to free resources it will kill your app , if you add some native code to handle this you could do some things to prevent android from doing this. However. It's NOT recommended to do this. If the user exits an app, it wants that, to close the app. If the user presses the home button, it wants to go to another app, and android will keep your app running for some time in case your user comes back to the app.
The best way to do this, is to handle the default flutter lifecycle to store important data in case the system kills the app.

stopping the user from forcing stop my app

About Android (6.0 to the last version)
I'm developing an app and we want that the user, once he accepts all the terms, don't be able to kill the process or force stop the app. Honestly, I'm completely lost right now, because on the last versions of android, and specially some brands like Xiaomi, we are having a lot of trouble with it, and we don't know how to act right now.
In the case that it could not be possible, could at least get an alert whenever the user is killing the app?
Thanks!!
It is not possible to prevent the user from killing an app. Android is a unique system where the app has no direct control over its lifecycle but the system has. The system can (and will, when required) kill the app or any of its processes at its own will. To make your app aware of these changes, the android framework provides for various callbacks such as onPause, onStop and onDestroy which are called in succession when the user kills the app.
Side Note : There is no guarantee that onDestroy() will be completely executed when the app is killed. Do not place essential code there.
Of course, you can block or try to prevent the user from closing your app by overriding the back, home and recent buttons but it is highly recommended not to do so. Even if you do so successfully, the user has other means to close your app such as rebooting their phone.
So what to do?
You are looking for a kiosk mode app. Kiosk mode is used for single purpose phones such as at a restaurant or for a cab driver. Kiosk mode apps lock down the user to only a specific app (or a specific set of apps).
For normal apps, it is not possible to prevent the user from force closing your app. You can only get alerts by checking for lifecycle changes as described above. Moreover, it is not at all recommended to change the natural behavior of the hardware buttons on android. The user can still find a way to close your app. If your app is doing something really essential which should proceed in the background, consider using a service for that instead. Also, the user can uninstall your app at anytime if they find your app being too intrusive and you won't be able to do anything in that scenario.
Tl;dr: Use kiosk mode to prevent the user from exiting the app. This will only allow the user to access your app(s) in their device.
Usually you cannot! Even if you try to disable some buttons, user can always stop app or restart device. In addition at times, the OS will stop the App. Your responsibility as a programmer is to program around this, and give the user the feel that it never stopped. If you are doing background monitoring, you will need to use service. Users will still be able to stop service. Having said that, you can set your app as a Device Administration app, see here, which may disallow stopping, but unless you are distributing internally to a company, noone will install.

How to determine which Apps are launched most by the user?

I am trying to build a sort of launcher.
I would like to have the possibility to present to the user the apps he uses most.
Is there any way to determine which Apps are launched more often by the user?
I am not aware of any system "counter" that does that, and I have found nothing in the documentation and in SO.
There is no way to get this information from the OS, because of privacy concerns. You can start collecting this information when people install your launcher and start using to launch apps, because you'll know which apps they start, but you have to start with some common list of apps initially, which likely will be useless to your users. You can also import their current home screen from the Launcher (and TouchWiz, and HTC Sense), but that does not scale easily for all possible launchers people might be currently using (Nova, GO Launcher, Facebook Home, and so on).
If you are creating an Android launcher, then you are responsible for displaying the android Applications installed and while clicking on the application icon that you listed, you are the one who is opening up the clicked app. So you can keep the count whenever you open a particular app and do accordingly.
Whenever you open an application, just save an open counter against the application package name of the app that you opened.

How to set my app as default home android?

I'm developing a Android application, and I would like that when it first starts it set itself as default action for Home button.
Currently this option is given to the user by the Android system only when he first press the Home button after running my app.
User don't want to click on check box as "Use by default for this action" it should be set by default my apps.
Thanks in advance.
This is not possible, and it is a good thing too.
Android allows users to choose their own defaults to prevent malicious apps from making themselves the default app to deal with an action, and hence protecting the user's data and device. If an app could set itself as the default homescreen or browser or call app etc. then it could steal the user's personal data and also potentially spoil or deny access to the device itself.
Due to the above reasons, this is not possible why the Android SDK, and I sincerely doubt that an unofficial means to do this exists.

Start application when Content provider is changed

I want my application to start when someone modifies a content provider. A setting to be specific. The settings framework calls "notify" when a value is set.
If my app was started I would use registerContentObserver() I guess, but is is not started.
Can define some intent-filter in my manifest that wakes up my application. A back up plan would be to have a service running all the time that has registered a listener, but that seems like a wast or resources.
Thanks, Ola
This isn't directly supported by the Android device because starting an app every time a ContentProvider's data changes is a path to really killing your battery. To do the query, you'd need to do it in a service, which as you said is understandably undesirable.
Secondly, starting an intent is a user action. Android really doesn't support allowing an application to start all on its own without user request... Doing so would be impolite! What if your user was doing something important and then your app pops up on top? Remember the user is in control, not you. Instead of starting an application, consider placing a Status Bar Notification so the user can deal with it when it's convenient for them.

Categories

Resources