0

I've implemented a library from github in my app. I want to know how to disable it after its first launch. I dont want it to be shown each time on app launch. heres what i've tried. I tried adding a boolean variable but it didnt work. This question isn't just for this topic, suppose i want to call a method ONLY AFTER FIRST TIME after app install, I dont want it to be called again once its called in first app launch time. i hope it's clear what i'm trying to achieve.

 boolean firstLoad;

    if(firstLoad=true) {

        TapTargetView.showFor(this,                 // `this` is an Activity
                TapTarget.forView(findViewById(R.id.button), "This is a target", "We have the best targets, believe me")
                        // All options below are optional
                        .outerCircleColor(R.color.colorPrimary)      // Specify a color for the outer circle
                        .outerCircleAlpha(0.96f)            // Specify the alpha amount for the outer circle
                        .targetCircleColor(R.color.colorAccent2)   // Specify a color for the target circle
                        .titleTextSize(20)                  // Specify the size (in sp) of the title text
                        .titleTextColor(R.color.colorAccent2)      // Specify the color of the title text

                new TapTargetView.Listener() {          // The listener can listen for regular clicks, long clicks or cancels
                    @Override
                    public void onTargetClick(TapTargetView view) {
                        super.onTargetClick(view);      // This call is optional

                    }
                });
    }

    firstLoad=false;
Phantômaxx
  • 37,901
  • 21
  • 84
  • 115
  • When first launched, create a boolean in SharedPreference and use that to control your logic and update boolean accordingly – denvercoder9 Dec 26 '17 at 18:12
  • Possible duplicate of [How to launch activity only once when app is opened for first time?](https://stackoverflow.com/questions/7238532/how-to-launch-activity-only-once-when-app-is-opened-for-first-time) – denvercoder9 Dec 26 '17 at 18:13
  • It's not an activity to be exact, it's a "Method" that I want to be disabled after first launch – user8747695 Dec 26 '17 at 18:15
  • same logic. have you even looked into the solutions in there? i guess not – denvercoder9 Dec 26 '17 at 19:17

1 Answers1

1
 Boolean firstLoad = getSharedPreferences("PREFERENCE", MODE_PRIVATE)
            .getBoolean("firstLoad", true);

    if (firstLoad) {

        //call your method

        getSharedPreferences("PREFERENCE", MODE_PRIVATE).edit().putBoolean("firstLoad", false).commit();

    }
lakshman.pasala
  • 565
  • 6
  • 16