Launch an activity only the first time the application starts - android

I need a way to detect if this is the first time the user is ever opening the application, if so, start an activity. Then all previous application launches wouldn't start that activity. I've read in a few places about using preferences to accomplish this. Anyone got any ideas?

Yeah, preferences is the way to go.
Check for the existence of the preference flag, if that exists you have already set, so your application was already started. Otherwise start your welcome activity and set the flag for future.

You can also disable one main activity and enable another one after your intro has run. See: the docs for PackageManager.setComponentEnabledSetting.

what if you have a user who deletes the application data in the device settings. This also removes the sharedPreferences data. The OP said he/she needs a way to determine if "ever" the user has opened an application. Shared Pref is not full proof.

Related

Android If registered launch service activity else launch registration activity

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.

Android: How to set activity that shows only once (when app is installed)

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.

right way to add starting tips in Android app

I am developing an Android application, and I want to show some tips (few slides) for user when applicationis started first time.
I can make an activity and start it in OnCreate method of main activity, or make dialog window.
I want to ask: how to make it in the right way? Can experienced developers advise something, maybe with example?
You have to first make sure that these tips are launched only on first launch of app. I have seen this done by displaying a Dialog, and saving a value to shared preferences (or in sqlite for that matter). On next app launch this value is checked, if it is set, then you don't display the Dialogs.
This seems to be the simplest way. Note that when the app is uninstalled and installed by again the Dialogs will be displayed again.
Sometime we want to give the user ability to see this Dialogs once again. You can do this by setting/resetting the value in shared preferences from the apps settings screen. The user can change the value here and see the Dialogs again on app start.
Just make a Dialog Type Activity and show it automatically at the first time startup of your application.
and also add a help in you menu so that user can see it whenever he/she need help.

Android: How do I restart my app by activity that I stopped by pressing the home?

When i stop my application pressing home button, i need that the app restart from the same activity when i open it again.
Now my application always start from main activity :(
(i don't know why but on emulator work correctly...)
There are a lot of options for preserving the state of an application - the ost common of these include using the bundle passed in OnCreate to initiate the application correctly.
I suggest you look at the android developers documentation as regards to activity lifespan.
When you begin an Activity, store a SharedPreference that records which Activity you are on. Check this preference when you enter your main Activity and, if set, jump to that Activity.
(If you are just looking for a way to get back to your Activity and don't care about the code, use the Recents menu to get back to your Activity. On devices with dedicated keys, long-press Home.)

I am facing unexpected issue in android app

I have two activities: Login and List.
When i log-in i display the list. When user is in the list activity and press the home button. After that clicks on the app icon it brings to login page for some times only. While it should display the list.
How to resolve this?
Your app is pushed out of memory sometimes in order to free memory for other apps. When it happens, app is re-launched when user enters it and first Activity is opened. The only(or not the only) way for you to maintain your app state is to store it somewhere. You could save whether user logged in or not in SharedPreferences and when Login Activity is created you could check this.
Sometimes your app will be killed depending on how much memory other applications need. Your application must save and restore its state in order to behave as if it hadn't been killed.
If you read the section on the Activity Lifecycle in the developer docs, you should understand what you need to do.

Categories

Resources