0

I'm currently working on implementing ShowcaseView into an app. My goal is to change views when the done button is pressed.

But once it changes to the new view, the whole code block runs again, and the ShowcaseView pops up again on the next page. Everything works properly until I add in the code to change views. How can I solve this?

Here is the code I have so far:

public void createShowView() {

    ShowcaseView sc =  new ShowcaseView.Builder(getActivity())
            .setTarget(new ViewTarget())
            .setContentTitle("")
            .setContentText("")
            .setStyle(R.style.CustomShowcaseTheme2)
            .hideOnTouchOutside()
            .setShowcaseEventListener(new SimpleShowcaseEventListener() {
                public void onShowcaseViewDidHide(ShowcaseView showcaseView) {
                    Intent tab2 = new Intent(getContext(), tabs.class);
                    tab2.putExtra("Specific Tab", 1);
                    startActivity(tab2);

                }
            })
            .build();


}

public void createDialog() {
    AlertDialog.Builder builder = new AlertDialog.Builder(getActivity());
    builder.setMessage("To view a full tutorial of ...., press continue.")
            .setTitle("View Tutorial");
    builder.setPositiveButton("Continue", new DialogInterface.OnClickListener() {
        @Override
        public void onClick(DialogInterface dialog, int which) {

            createShowView();

        }
    });
    builder.setNegativeButton("Skip Tutorial", new DialogInterface.OnClickListener() {
        @Override
        public void onClick(DialogInterface dialog, int which) {

            getActivity().getSharedPreferences("PREFERENCE", Context.MODE_PRIVATE).edit()
                    .putBoolean("isfirstrun", false)
                    .commit();

        }
    });

        AlertDialog dialog = builder.create();
        dialog.show();

}

@Override
public void onActivityCreated(@Nullable Bundle savedInstanceState) {
    super.onActivityCreated(savedInstanceState);
    Boolean isFirstRun = this.getActivity().getSharedPreferences("PREFERENCE", Context.MODE_PRIVATE)
            .getBoolean("isfirstrun", true);

    if (isFirstRun) {


        createDialog();



    }

}
mkrieger1
  • 19,194
  • 5
  • 54
  • 65
Dan Grueneberg
  • 215
  • 1
  • 4
  • 9
  • What exactly do you mean by "change views"? Are you referring to the `Intent`/`startActivity()` block? – Mike M. May 21 '17 at 01:21
  • Yes, that's what I'm referring to. – Dan Grueneberg May 21 '17 at 01:27
  • OK, well that's starting a brand new instance of `tabs`, and it will load up and initialize from the start, just like when you launched it. (I'm assuming that's the `Activity` that you're using `ShowcaseView` in.) You probably don't want to do that. Instead, it sounds like you just want to change tabs in the current instance, however you happen to be handling those. – Mike M. May 21 '17 at 01:35

0 Answers0