Antonio Juan
Antonio Juan

Reputation: 21

First time open my app, request data and save them

I am making an application. I want the first time the user opens my application, display an initial screen for entering the Name, Email and Phone Number, Then, store the input data in the memory of the mobile phone.

I want this screen appears only the first time the user opens the application, because in my application always the same Name, Email and Phone will be used.

How I can do it?

Upvotes: 0

Views: 134

Answers (1)

Chirag
Chirag

Reputation: 56925

For only first time view either you can either use shared preference or database.

Once user enter the values store all the values in shared preference and set one flag true in shared preference, when again next time user open the application check the flag if it is true then move to next screen either open the screen for entering name, email and phone number

Setting value in shared preference

SharedPreferences.Editor editor = getSharedPreferences(MY_PREFS_NAME, MODE_PRIVATE).edit();
 editor.putString("name", "test");
 editor.putInt("id", 12);
 editor.commit();

Retrieve from Shared Preference

SharedPreferences prefs = getSharedPreferences(MY_PREFS_NAME, MODE_PRIVATE); 
  String name = prefs.getString("name", "No name");//"No name" is the default value.
  int idName = prefs.getInt("idName", 0); //0 is the default value.

Upvotes: 2

Related Questions