0

I would like that animation on MainActivity to be exhibited only when the user opens the app, but remains static if the user comes from another Activity/Fragment (e.g. by using BottomNavigationMenu), so as not to pollute the window too much.

I think it can be solved by using onCreate, onStart, onResume but I am unable to set it properly (still learning).

The only answer I found is here: https://www.tutorialspoint.com/how-to-launch-activity-only-once-when-android-app-is-opened-for-the-first-time but it is not what I want since I still would like the animation to be exhibited every time the app opens. Thank you in advance.

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

         // execute animation here??
}

override fun onStart() {
        super.onStart()
        setContentView(R.layout.activity_main)

        // logic part (buttons) is executed here??
}
klinxz
  • 3
  • 1
  • 3

1 Answers1

1

Once the Main activity is loaded then you have to finish() from other Activity/Fragment then onResume() override method Main Activity will be called. Do not start Main activity every time if the user comes from another Activity/Fragment.

For fragments:

activity.finish()

For Activity:

finish()

Rather then:

Intent startIntent = new Intent(context, MainActivity.class);
startIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);        
context.startActivity(startIntent);
  • I understood the part where you say I don´t have to start Main Activity every time. However, I didn´t figure out how to do so by using finish(). I am new to Android, so I am missing something. Following your suggestion I found this post: https://stackoverflow.com/questions/10847526/what-is-activity-finish-method-doing-exactly To explain what I am trying to do: 1) User opens the app -> exhibits the animation; 2) User comes from another activity -> skip the animation and load all the rest. I will keep trying. Thank you for your help! – klinxz Jun 26 '21 at 16:53
  • when the user return from other activity you have to call finish() before returning to previous activity. – Umair Anjum Jun 26 '21 at 17:41