Add this code to the onCreate method
SharedPreferences pref = getSharedPreferences("ActivityPREF", Context.MODE_PRIVATE); if(pref.getBoolean("activity_executed", false)){ Intent intent = new Intent(this, TutorialOne.class); startActivity(intent); finish(); } else { Editor ed = pref.edit(); ed.putBoolean("activity_executed", true); ed.commit(); }
SharedPreferences will be stored every time the application runs, unless you clear the data from the settings on your Android. The first time you get the value from the boolean (activity_executed) stored in such preferences (ActivityPREF).
If it does not find a value, it will return false, so we need to edit the preference and set it to true. The next run will launch the TutorialOne action.
finish() erases the current activity from the stack history, so returning is not possible using the button back from TutorialOne.
In your manifest, you can install this actitiy with
<intent-filter> <action android:name="android.intent.action.MAIN" /> <category android:name="android.intent.category.LAUNCHER" /> </intent-filter>
Each time the application is executed, it launches this action, but due to the true value set to "activity_executed" , a new action will be launched using startActivity .
source share