To add an OnboardingSupportFragment
to your app, implement a class that extends the OnboardingSupportFragment
class. Add this fragment to an activity, either via the activity's layout XML, or programmatically. Make sure the activity or fragment is using a theme derived from Theme_Leanback_Onboarding
, as described in Customize themes.
In the onCreate()
method of your app's main activity, call startActivity()
with an Intent
that points to your OnboardingSupportFragment's
parent activity. This ensures that your OnboardingSupportFragment
appears as soon as your app starts.
To ensure that the OnboardingSupportFragment
only appears the first time that the user starts your app, use a SharedPreferences
object to track whether the user has already viewed the OnboardingSupportFragment
. Define a boolean value that changes to true when the user finishes viewing the OnboardingSupportFragment
. Check this value in your main activity’s onCreate()
, and only start the OnboardingSupportFragment
parent activity if the value is false. The following example shows an override of onCreate()
that checks for a SharedPreferences
value and, if not set to true, calls startActivity()
to show the OnboardingSupportFragment
:
Comments
Post a Comment