Welcome to the Treehouse Community
Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.
Looking to learn something new?
Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.
Start your free trial
titi khalil
Courses Plus Student 368 Pointsplease help me i want to create an activity that works only one time whene the app run for the first time
Emergency
3 Answers
Andrei Fecioru
15,059 PointsIn that case you need to save a boolean flag in the application's user preferences and based on the value you read from there during application startup you want to bypass (or not) that particular activity.
Below is a StackOverflow link with a very basic example about the usage of Android's User Preferences APIs:
http://stackoverflow.com/questions/23024831/android-shared-preferences-example
Even a better link from the Android dev site:
http://developer.android.com/guide/topics/data/data-storage.html#pref
Andrei Fecioru
15,059 PointsYou need to make sure that after the first time your activity is shown and you navigate away from it, you remove that particular activity from the activity stack (so that it will not show when you press the back button on the device).
You can implement this from your AndroidManifest.xml file, just by adding [android:noHistory="true"] attribute in those activity XML elements for which you want to have this type of behaviour enabled.
Hope this helps.
titi khalil
Courses Plus Student 368 Pointsthnx but i'm not looking for this solution , I want to creat an activity contain instruction for my app and i want it to show just one time when the user open it for the first time after that disappear only if the user delete the data of the app