-4

How to show a Activity only once. It should be shown only when the app is opened at first time. If the user visits 2nd or any other time. The main activity should be displayed.. Ex:- Uc browser... How to do like this .. is there any one help me

mach
  • 8,315
  • 3
  • 33
  • 51
Sathish Kumar
  • 919
  • 1
  • 13
  • 27

3 Answers3

1

Create a LaunchActivity that will direct you to either the MainActivity or the ShowOnlyOnceActivity.

Add a SharedPref value, which will be set once the ShowOnlyOnceActivity is shown. Then from the LaunchActivity, if the SharedPref is already set, go straight to MainActivity.

harrane
  • 959
  • 11
  • 24
0

When you start the phone activity you can check a preference SharedPreference in the onCreate. If you need to show another activity instead just route immediately to that activity.

 http://developer.android.com/reference/android/content/SharedPreferences.html

Altenatively, if it is just a message you could show a dialog or do an overlay in the layout of the home page that is only visible on the first use. Again, use the SharedPreference to decide if you have seen the first time page.

mjstam
  • 1,049
  • 1
  • 6
  • 5
-2

See for flags Intent.FLAG_ACTIVITY_SINGLE_TOP and Intent.FLAG_ACTIVITY_CLEAR_TOP if launched from code.

If launched from xml (manifest), look at android:launchMode="singleTop" (or other value) from activity tag. http://developer.android.com/guide/topics/manifest/activity-element.html

Apollo
  • 196
  • 1
  • 9
  • 2
    This OP wants to run code a single time; essentially, they need a way to remember that they've run it. Your answer doesn't make any sense. – Lynn Crumbling Mar 02 '15 at 15:34