Basically, I want to have a screen/view that will open when the user opens up the app for the first time. This will be a login screen type of thing.
there are classes SplashActivity
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
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()
}
class MainActivity
class MainActivity : AppCompatActivity() {
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContentView(R.layout.layout_activity_main)
window.addFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON)
about.setOnClickListener{
val intent = Intent(this,ScondActivity::class.java)
startActivity(intent);
}
val assistantFragment = AimyboxAssistantFragment()
supportFragmentManager.beginTransaction().apply {
replace(R.id.assistant_container, assistantFragment)
commit()
}
}
override fun onBackPressed() {
val assistantFragment = (supportFragmentManager.findFragmentById(R.id.assistant_container)
as? AimyboxAssistantFragment)
if (assistantFragment?.onBackPressed() != true) super.onBackPressed()
}
}
We suggest to don't declare MyCustomAppIntro as your first Activity unless you want the intro to launch every time your app starts. Ideally you should show the AppIntro activity only once to the user, and you should hide it once completed (you can use a flag in the SharedPreferences) ????
question from:
https://stackoverflow.com/questions/65651306/check-if-an-application-is-on-its-first-run-with-kotlin 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…