ShowCaseView is not called from onCreate with SharedPreferences

84 Views Asked by At

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);
}

First of all I want to thank @Sambhav. K

However, I followed all the steps as you wrote in your comment, but I still didn't get the desired result, my ShowCaseView doesn't show up when I first call the app :(

P.S. now working on minSDK23, thanks

   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

    SpannableStringBuilder ssb = new SpannableStringBuilder(getString(R.string.showcaseview_body));

    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();

    tinyDB.putBoolean(KEY_FIRST_TIME_OPEN, false); // very important
    }else{
         // the app already opened. Do not show the target
            }
      ...
        }
    }
0

There are 0 best solutions below