Home > other >  How to move from Secondactivity to Mainactivity after animation is complete?
How to move from Secondactivity to Mainactivity after animation is complete?

Time:04-24

Sorry I am a bit new to stack overflow but hopefully the question is understandable!

I talked to a staff memeber/community member who showed me Intent to go from 1 activity(in my case GlobeActivity where my animation is stored) to another activity( MainActivity where username/password is stored). But the animation does not show up, instead it cuts directly to MainActivity.

Anyone got some suggestions to why and how to make it so that when animation is finished, it re-directs/ transitions to MainActivity without use of buttons?

Here is my code so far:

GlobeActivity( my SecondActivity):

package com.example.testerino2022

import android.content.Intent
import androidx.appcompat.app.AppCompatActivity
import android.os.Bundle
import android.widget.TextView

class GlobeActivity : AppCompatActivity() {
    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        setContentView(R.layout.activity_globe)

        supportActionBar?.hide()

        val textView = findViewById<TextView>(R.id.textGlobeScreen)
        textView.animate().translationX(1050F).setDuration(1000).setStartDelay(2500)

        val intent = Intent(this, MainActivity::class.java)
        startActivity(intent)
        finish()
    }

}

MainActivity(has default code in it );

class MainActivity : AppCompatActivity() {
    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        setContentView(R.layout.activity_main)

    }
}

CodePudding user response:

Have you changed the launcher activity from MainActivity to GlobeActivity in the app's manifest?

CodePudding user response:

You can use animation listener

 textView.animate().translationX(1050F).setDuration(1000).setStartDelay(2500).setListener(
        object: Animator.AnimatorListener{
            override fun onAnimationStart(p0: Animator?) {
                TODO("Not yet implemented")
            }

            override fun onAnimationEnd(p0: Animator?) {
                val intent = Intent(this, MainActivity::class.java)
                startActivity(intent)
                finish()
            }

            override fun onAnimationCancel(p0: Animator?) {
                TODO("Not yet implemented")
            }

            override fun onAnimationRepeat(p0: Animator?) {
                TODO("Not yet implemented")
            }

        }
    )

CodePudding user response:

Handler(Looper.getMainLooper()).postDelayed({
            val intent = Intent(this, LoginActivity::class.java)
            startActivity(intent)
            finish()
        }, 3500)
  • Related