I would like to show the ShowCaseView only once when starting the app for the first time. I use SharedPreferences but when I call from onCreate, nothing happens, ShowCaseView is not displayed, when I delete SharedPreferences then ShowCaseView is displayed. What to do, please help.
SpannableStringBuilder ssb = new SpannableStringBuilder(getString(R.string.showcaseview_body));
if (!LoadPreferencesBoolean(getApplicationContext(), "firsttimeshow", false)) {
new MaterialTapTargetPrompt.Builder(MainActivity.this)
.setTarget(R.id.settings_menu)
.setPrimaryText(R.string.showcaseview_settings_title)
.setSecondaryText(ssb)
.setPromptStateChangeListener(new MaterialTapTargetPrompt.PromptStateChangeListener() {
@Override
public void onPromptStateChanged(MaterialTapTargetPrompt prompt, int state) {
if (state == MaterialTapTargetPrompt.STATE_FOCAL_PRESSED) {
}
}
})
.show();
ShowCaseViewPreferences(getApplicationContext(), "firsttimeshow", true);
}
CodePudding user response:
For this, you can use my library from here. You can use it this way to do the simple tasks in the app like yours.
But, to use it, first add it to your app like this:
- Add nitpick to your
settings.gradle
file like this:
maven { url 'https://jitpack.io' }
- Add the library to your
build.gradle
file like this:
implementation 'com.github.sambhav2358:TinyDB:1.91'
- Click
Sync now
.
Now, you can easily use the library like given below
Try this in the activity:
public class MyActivity extends AppCompatActivity {
//add these variable
TinyDBManager tinyDB;
private final String KEY_FIRST_TIME_OPEN = "kfto";
...
@Override
public void onCreate(Bundle mBundle){
tinyDB = TinyDB.getInstance(this);
boolean isOpeningFirstTime = tinyDB.getBoolean(KEY_FIRST_TIME_OPEN, true);
if(isOpeningFirstTime){
// the app opened first time. Show the target
tinyDB.putBoolean(KEY_FIRST_TIME_OPEN, false); // very important
}else{
// the app already opened. Do not show the target
}
...
}
}
CodePudding user response:
maybe your sharedPreferences return true and your condition equal false. check with debug.