0

Помогите разобраться и реализовать метод показ AppIntro только при первом запуске. AppIntro создал по этому ресурсу https://github.com/AppIntro/AppIntro Имею SplashActivity ,MyCustomAppIntro, MainActivity. Показ при первом запуске : сперва всегда со Splash затем MyCustomAppIntro и MainActivity. Если запуск не первый : Splash и MainActivity

class SplashActivity : AppCompatActivity() {


    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)

        //hiding title bar of this activity
        window.requestFeature(Window.FEATURE_NO_TITLE)
        //making this activity full screen
        window.setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN, WindowManager.LayoutParams.FLAG_FULLSCREEN)
        setContentView(R.layout.activity_splash)

        //4second splash time
        Handler().postDelayed({
            //start main activity
            startActivity(Intent(this@SplashActivity, MyCustomAppIntro::class.java))
            //finish this activity
            finish()
        },2000)
    }
}

Следующий класс

class MyCustomAppIntro : AppIntro() {




    companion object {
        fun startActivity(context: Context) {
            val intent = Intent(context, MyCustomAppIntro::class.java)
            context.startActivity(intent)

        }
    }
    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)

        setTransformer(AppIntroPageTransformerType.Depth)
        // You can customize your parallax parameters in the constructors.
        setTransformer(AppIntroPageTransformerType.Parallax(
                titleParallaxFactor = 1.0,
                imageParallaxFactor = -1.0,
                descriptionParallaxFactor = 2.0
        ))

             // Make sure you don't call setContentView!

        // Call addSlide passing your Fragments.
        // You can use AppIntroFragment to use a pre-built fragment
        addSlide(
            AppIntroFragment.newInstance(
            imageDrawable = R.drawable.ayana,
                backgroundDrawable = R.color.black,
                        description = "Привет мой друг"

        ))
        addSlide(
                AppIntroFragment.newInstance(
                        imageDrawable = R.drawable.ayana,
                        backgroundDrawable = R.color.black,
                        description = "Меня зовут AYANA"
        ))
        addSlide(
                AppIntroFragment.newInstance(
                        backgroundDrawable = R.drawable.screen_3

                ))
    }

    override fun onSkipPressed(currentFragment: Fragment?) {
        super.onSkipPressed(currentFragment)
        // Decide what to do when the user clicks on "Skip"
        val intent = Intent(this,MainActivity::class.java)
        startActivity(intent);


        finish()
    }

    override fun onDonePressed(currentFragment: Fragment?) {
        super.onDonePressed(currentFragment)
        val intent = Intent(this,MainActivity::class.java)
        startActivity(intent);
        finish()
    }

И MainActivity

1 ответ 1

1

Добавил в splash

Handler().postDelayed({
            //start main activity

            val sharedpref: SharedPreferences =
                getApplicationContext().getSharedPreferences(
                    "com.justai.aimybox.assistant",
                    MODE_PRIVATE
                )

            val token: String? = sharedpref.getString("token", null)
            if (token == "False" || token == null) {
                // rest of the FirstTime Logic here
                startActivity(Intent(this@SplashActivity, MyCustomAppIntro::class.java))

                sharedpref.edit().putString("token", "true").apply()
            } else {
                // rest of the Not-FirstTime Logic here
                startActivity(Intent(this@SplashActivity, MainActivity::class.java))
            }
            //startActivity(Intent(this@SplashActivity, MyCustomAppIntro::class.java))
            //finish this activity
            finish()
        },2000)

Ваш ответ

By clicking “Отправить ответ”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Всё ещё ищете ответ? Посмотрите другие вопросы с метками или задайте свой вопрос.