How to clear memory when user Log off the app - java

I am making an app that user has to Log in and connect to a Server. And i have maps, pins, a lot of bitmaps and variables, however, I want variables and other unnecessary to be cleared on user Log off
What i want is like a restart the app, like when the user open the app for first time.
I heared about:
android.os.Process.killProcess()
but not sure when it actually does and how i can call it...

Related

App freezes on splash screen for some users

Some users report an issue: they launch the app, the splash screen appears, but nothing else happens. Splash screen just stays on without ANR or errors.
I can't see any logs because no loggers were initialized yet, and I don't even know if the onCreate method was called.
Important notes:
99% of users don't experience this
users that report such issue say that it's persistent - they can't use the app at all
some users say if they launch google play store first and then launch app - it works fine, but without that step it always freezes at the splash screen, so they have to launch google play store each time before launching the app
To send any data anywhere I need to initialize a bunch of dependencies, but looks like it doesn't even get to that point. App works fine on millions of devices, but a few thousand users reported this issue. Cannot post application initialization code as it's huge.
Questions:
What can possibly be the reason of this?
Where would be the best place to start searching for the bug?
Is there a way to determine the first line of code where the app is not launching as it should?
Is there something that the google play store triggers that applications need to launch properly?
It was because of googlePlayStoreAppUpdateManager.appUpdateInfo check for updates that returns a Task, but sometimes it doesn't actually call nor success nor fail listeners, so we hang forever. Solution was to add RxJava wrapper with timeout and limit waiting time for Google to answer to some reasonable time.
It looks like some devices, like Xiaomi or Honor are not allowing google play manager to check for updates unless explicitly started by the user, so this check should be done carefully.

Android session handling

How do I manage a session in an Android app after the user successfully logs in? Should I use SharedPreferences or static variables to store the session info?
The user must log in every time the app launches too.
Try to use Account Manager. It was designed for it. Here is a tutorial for it.
Anyway it is not recomended to use preferences for it, because at the end it is plain XML file, so anyone can steal data from it. Also it is not recomended to use static variables, because you never know when your process will be killed. For example somebody could call to your phone and android could kill your app and restart it after call ends.

Sharing user between two apps when one is a system app

I found many references to shared user IDs among two apps and it looks like what I'm looking for.
What I'm concerned about is that there are statements like permissions will be shared between the apps. If one of the apps is a system app, does that mean that the normal app will have system privileges too?
I want one app to be a regular app and one app to be a system one. I don't want the regular app to have any of the system admin privileges.
We are doing this so we can share a Content Provider. Our data is on the edge of being complicated enough for this, but I feel it's justified.
It appears that this is something you can't do. If you set up your system app as shared, you don't get any kind of an error, but Android appears to refuse to acknowledge it.
I took shared back out of my manifest file and it is working fine now.
Live and learn...

How to prevent an Android application from being installed more than three times?

I have got a suggestion to restrict an Android application to be installed a limited number of times, let's suppose three times for a given user account. I have already inserted a form at the start of the application which checks for username and password from our database, and returns whether its valid or not.
Next I have to apply a trick to prevent this application from being installed more than three times by each user. I hope it clears what I am trying to do. Any ideas what to do and how to proceed?
By no means you can restrict user to not to install your application from google play.
Have a install_count column in the user table in your database. Each time the user fills out form, check for the install_count value, if it is equal to 3, then don't allow the application to continue, you can show a message like "max installs exceeded" and exit the app. Otherwise, increment the install_count value in the db for that user.
PS: As Zoombie said, you can't stop the user from installing the app, but you can restrict the user from running the application if installation limit exceeds.
Also you need to be aware, there are many apps which take a back up of the installed app and data that can be restored back anytime. More over, if the user changes his device more than thrice, he won't be able to run your application. So consider the drawbacks of this limitation.
Technically this isn't a very difficult problem but the issue of user relations will be difficult to manage. You should provide a simple and easy mechanism for your users to "reset" their install count. Additionally you need to inform your users of this restriction BEFORE they pay for your app.
Restrictions like this will result in problems in a few cases I can think of:
What happens if a user factory resets their phone and then re-installs the app?
What if the user installs a custom ROM or gets a new phone?
Are you going to deny a paying customer the ability to install an application that they paid for? Poorly enforcing a policy like this will only hurt you in the long run as it will result in
very bad reviews of your app
piracy of your app with the checks removed
Remember people are downloading/buying your app because it provides something to them and with that they assume that they'll always have access to your app. As soon as you start denying functionality or violating their assumptions you're going to start alienating your customers.

Can I monitor when an app has been closed? For example when a user closes Maps(or any other app) can I make a popup come up saying "you closed maps"

I basically want to add a feature to an app I am making but it would require me to know when the user closes certain apps. For example if the user closes any of the following; Maps, Firefox, Facebook, and Camera, A yes/no notification, kinda specific to the app, would come up for the user to answer.
It's something that sounds complicated i know but im pretty sure I've seen it done on a few android apps before.
Thanks
edit: so i was thinking since tasker can perform a task upon opening an app and then stopping the task when closing the app i can do what i want right?
The closest option available for monitoring the status of other applications and packages is through the use of a BroadcastReceiver registered to listen for Intents related to packages or applications. I looked through the intents available (the actions are constants with names starting with ACTION_), and none were directly related to another application closing, however you may be able to capture something, such as a changed battery status, that can look at the status of running applications in question.

Categories

Resources