Android variables retaining values after uninstalling the app - android

I need a way to be able to tell if a user has uninstalled and reinstalled the android application. I use shared preferences for when the user CLOSES the app, however, I need to save out a variable that will let me know if the user has ever opened the app on this device in the past.
(Basically the user is awarded items in the game when first starting the game, after they are used the player could essentially just uninstall and reinstall and use the items again) I need a variable that gets saved in the android registry that will tell me if the player has ever opened the app before (even if they have previously uninstalled).
Is this possible?

Related

Android App restarts when I open it on my phone

I'm currently using a Samsung Galaxy S4.
I'm developing an app and as long as I don't exit it, it works great. However, if I leave it, it sometimes restarts itself completely and brings up the Login Activity.
I could select it from the active apps list, and it won't happen. If I go and open it up through pressing its app icon, it will sometimes restart. It will definitely restart if I remove it from the active apps list. How do I have it always return to its previous state in the app? Facebook manages it even when the app is removed from the active apps list.
Is Android garbage collecting my app for memory optimization? How would I avoid this.
The onPause() and onResume() methods might be what you're looking for. Check the Facebook SDK for details on persistent authentication, even when the app is closed. Check this SO post out for more details How to keep android applications always be logged in state?
And no, I don't believe this is Android doing any garbage collection.
Add this to the activity tag of your manifest to tell Android that your app will handle any configuration changes itself: android:configChanges="orientation|keyboardHidden"
To prevent users logging in each visit you can use shared preferences to save login credentials

how to block an application in android after using several times?

I created an application for pharma.
Now I want to stop that application after launching 10 times, and also even user can not launch an app after uninstall and reinstall the app.
How could I do that?
Does anyone have an idea?
Now i want to stop that application after launching 10 times
You are welcome to maintain some sort of counter and disable your launch activity when it should no longer be used, via PackageManager and setComponentEnabledSetting().
and also even user can not launch an app after uninstall and reinstall the app
This is not possible. You can store your counter on external storage, some place that will be retained even after an uninstall. However, the user can get rid of your counter file whenever the user wants.
If your application uses net connection you can send a parameter to your service with unique device id. In your service you get the device id and compare with your database. If device id is not in the database (first open of app) create a row with device id and the time stamp.
Everytime the user opens the app control the timestamp with today. If it is more than 10 days you can lock the app.
You can use SharedPreferences.
Create an int variable = 0 and store it to SharedPreferences
In onCreate method, increment this variable
Check (In onCreate method), if this variable > 10 - call finish()
Thats all. Hope this help.

Android App quits automatically if its idle for some hours

I created an new Android app and succeeded in its working. Its all functionality are working fine. While starting it will ask use name and password.
What my problem was "If my Application is idle for some 4 to 5 hours, then automatically it get quit , while restarting its again asking to login"
I need to know how to avoid automatic quit of my app.
I'm sorry if its simple or already asked quetions.
I need to know how to avoid automatic quit of my app.
No, you do not. Simply redirect the user to log in again, or, as #Rasel suggests, persistently cache credentials in a file or database or something.
Android applications do not and must not live forever. Phones have limited RAM. Android will terminate unused applications after a period of inactivity, to free up RAM for other applications. This is perfectly normal, just as it is perfectly normal for a user to close a Web browser after visiting a Web app.
Its completely natural for the android application.Android OS automatically kill the process when it needs to do.So if you want keep your application alive you have to think differently.To keep always running you can use service that will monitor your application states and handle the situation when it prompts for the login info again.
Another option you can write the login information in the shared preference and can clean when user intentionally leave the application.So when starting again if you find the information you can directly prompt to the user without entering the login information

Is there anyway to know that application launches firsttime?

Is there anyway to know that when an application is launched for the firsttime? I dont want to use sharedpref because when the user cleardata manually it clears all the data.
That is the point of clearing data, the user may want to tell your app to consider itself freshly installed without having to necessarily uninstall the app. You should not be trying to break that expectation. That said.....
You could create a file on the SD card and check for the existence of that file to determine if your app is being run for the first time.
Do not use the normal openFileOutput() calls in android as that will be cleared when the user clears data as well.
Unless the user wipes all files on the SD card, the file should remain in existence. Also, you can do both, a shared preference and the file and then check for one or the other, just in case.
Use your own server. Just store the unique android id on your server in the first time user launches your application. But you need internet for this.

Want to do work on my Application Uninstall:android

i am aware of android BROADCAST_PACKAGE_REMOVED for notify when any application is uninstalling from device.
Now it is possible that when i uninstall one application and that application do some work before and uninstall.
e.g: my application work with android contact if application uninstall at that time i want to change in contact data.
can i get any event for uninstalling app?
Thanks.
No.
(at least until the current version of Android)
In case it's any help, widgets do get notified when their last instance is removed. However, the app than contains the widget remains installed.

Categories

Resources