[Solved] I want to design an ANDROID app which sets user mobile number by taking input from them and after that it always shows next activity using service? [closed]


@Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);

        SharedPreferences sharedPref = PreferenceManager.getDefaultSharedPreferences(context);
       if(sharedPref.getBoolean("isFirstTime", true)){
            Intent startWelcomeScreen = new Intent(this,Welcome.class);
            startActivity(startWelcomeScreen);
            finish();
            Intent startWelcomeScreen = new Intent(this,Welcome.class);
            startActivity(startWelcomeScreen);
            finish();
        }

        setContentView(R.layout.activity_main);
}

MainActivity.java

If your app is executing for the first time, then it is redirected to Welcome screen. Notice the finish() call in the Main Activity. It is important, otherwise the back button will take you to the mainActivity, which is of course not what you want.

SharedPreferences sharedPref = PreferenceManager.getDefaultSharedPreferences(context);
        SharedPreferences.Editor editor = sharedPref.edit();
        editor.putBoolean("isFirstTime", false);
        editor.commit();

Welcome.java

You can also use,

editor.apply();

It does the job asynchronously, I suppose.

solved I want to design an ANDROID app which sets user mobile number by taking input from them and after that it always shows next activity using service? [closed]