My application start with Login. At time of login I am starting one service, and redirecting to another activity as Home. During this i am using SharedPreferences to directly launch Home activity instead of Login activity again. But when I am reinsatlling APK service stops. So i am thinking of clearing SharedPreferences while reinstalling so that apllication launch to Login activity instead of Home. So that user Login to appliaction again and service start again.
A shared preference and sqlite db doesnt get removed on a reinstall.
To delete them, go to
Settings-->Appications-->Manage Applications-->Click on you application-->Click on "Clear Data" on emulator. this will clear the data stored.
When you install an application, there is ACTION_PACKAGE_ADDED broadcast sent, however an installed application does not receive it.
When you uninstall application, it is not even called.
Summary - it's impossible to catch those events from your own application.
Related
I need to retain some information so that I can access it when I launch my app after it is closed. I need to use that information on 'onCreate()' of my 'MainActivity'. But I need to clear/reset those information if the mobile is rebooted. So how do I know in the program if the mobile has been rebooted and the activity is launched for the first time after reboot?
Listen for the BOOT_COMPLETED broadcast to know when the phone has been turned on.
Then use SharedPreferences.Editor.clear() followed by a commit() to delete all data for your app.
I click button home or recent application to close app and then I open app from recent application. Now I want if time I close app larger 5s my app will restart. How to do it? thank everyone
You can achieve this by SharedPreferences and implementing own logic, like when you will press home button store the current time in onPause() method and when the user opens the app again then check with the condition with the current time in onResume() and the stored value, if its more than 5s then restart it.
One thing remember, when restarting the activity store some negative number in SharedPreference so that, it won't restart again. And to restart the activity write below logic.
Intent intent = getIntent();
finish();
startActivity(intent);
I was wondering how to make my app launch the service activity if the user is already registered?, it wont have login activity but registration activity. So the app will start with the registration activity, after registration it will go to the service activity. When user closes the app, how to make it launch again from the service activity and not from registration activity?
How to make it recognize if it is registered go to the service activity and if it is not launch the registration activity(login data will be stored in sharedpreferences I dont know any other way how to do it though in case it disconnects it will have to reconnect again)
I will appreciate any answer, Thanks.
Normally for actions such as this I have an api where users login and if registered information then true is sent back, auto login if shared prefences found. If not then ask them to register. Keeping it in shared preferences isn't bad though, it will save on shut downs and should be fine.
Bearing in mind that if the user clears the data or uninstalls the application, then the shared preferences will be lost and the user would have to re-register to use again as there is no Login Activity.
If this is something that does not bother you then Ashley Alvarado is correct, and shared prefs is fine.
You can use SQLite for storing values as well but it all depends on your app and how you want it.
I would think if you wanted something more serious then I think server side data would be the way to go, but would take some researching.
I'm currently doing something similar and I do use Shared Preferences in my app and SQLite as well. I'm trying to learn different ways to learn as I go.
Hope this helps.
I want to make application with activity "UserIntro" that shows ONLY when app is installed and asks user some questions about himself. But latter when user starts app again that activity doesn't appear.
Does anyone know how to accomplish that?
Thank you for the answers!
Use Shared preferences to store a boolean first time the app launches. As the boolean won't exist first time, just check for it's existance upon startup and manually launch an activity.
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.