Skip to content

Snappy1

  • Home
  • Android
  • What
  • How
  • Is
  • Can
  • Does
  • Do
  • Why
  • Are
  • Who
  • Toggle search form

[FIXED] android – startActivity skips onCreate()

Posted on November 11, 2022 By

Solution 1 :

You overrode the wrong onCreate – you do not want to use the PersistableBundle version. Change your onCreate to only take the savedInstanceState: Bundle? parameter:

override fun onCreate(savedInstanceState: Bundle?) {
    super.onCreate(savedInstanceState)
    Timber.d("onCreate") // Now it'll be called
}

Problem :

I have a simple case of Activity1 -> Activity2.

In the past when I’ve used startActivity(Intent(this, Activity2::class.java)) there have been no issues and the onCreate() method of Activity2 would be called.

In my current case this is not happening. I have logs in the onCreate() method and they are never hit. But if I create a onStart() method it enters there. However, never in my logs for the lifetime of the application does onCreate() of Activity2 ever get hit. How is this possible. onCreate is a requirement before onStart I thought.

Here is the actual code I’m referencing above.

class Activity1 : AppCompatActivity() {

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

        setContentView(R.layout.activity_splash)

        startActivity(Activity2.getIntent(this))
    }
}

class Activity2 : AppCompatActivity() {

    override fun onCreate(savedInstanceState: Bundle?, persistentState: PersistableBundle?) {
        super.onCreate(savedInstanceState, persistentState)
        Timber.d("onCreate") // Never gets touched
    }

    override fun onStart() {
        super.onStart()
        Timber.d("onStart"); // Is hit with no problems.
    }

    companion object {
        fun getIntent(@NonNull context: Context) : Intent {
            return Intent(context, Activity2::class.java)
        }
    }
}

Comments

Comment posted by Cayce K

Damn… I feel so dumb 🙁 Should I just delete this question? I don’t know how I messed that up.

Comment posted by ianhanniballake

Nah, it’ll probably help someone else down the line that runs into the exact same problem. Easy to miss when you’ve been staring at it for too long 🙂

READ  [FIXED] android - Flutter image_picker permission can't find a valid activity to handle the request
Powered by Inline Related Posts
Android Tags:android, kotlin

Post navigation

Previous Post: [FIXED] java – The Android LoaderManager is deprecated. Now what?
Next Post: [FIXED] android – Is WorkManager the right solution for me?

Related Posts

[FIXED] Implementing the Huawei IAP on Android Android
[FIXED] python – Kivy APK invalid signature unable to upload on google play Android
[FIXED] android – How to constraint views/widgets to barriers using AS 3.6.3 Android
[FIXED] android – The application may be doing too much work on its main thread. when i lunch Fragment or Activity and inside both of them i m using firebase Android
[FIXED] kotlin – Creating OnCompletionListener in Compose Android
[FIXED] How to start appium server from my python code with AppiumService()? Android

Archives

  • March 2023
  • February 2023
  • January 2023
  • December 2022
  • November 2022
  • October 2022
  • September 2022

Categories

  • ¿Cómo
  • ¿Cuál
  • ¿Cuándo
  • ¿Cuántas
  • ¿Cuánto
  • ¿Qué
  • Android
  • Are
  • At
  • C'est
  • Can
  • Comment
  • Did
  • Do
  • Does
  • Est-ce
  • Est-il
  • For
  • Has
  • Hat
  • How
  • In
  • Is
  • Ist
  • Kann
  • Où
  • Pourquoi
  • Quand
  • Quel
  • Quelle
  • Quelles
  • Quels
  • Qui
  • Should
  • Sind
  • Sollte
  • Uncategorized
  • Wann
  • Warum
  • Was
  • Welche
  • Welchen
  • Welcher
  • Welches
  • Were
  • What
  • What's
  • When
  • Where
  • Which
  • Who
  • Who's
  • Why
  • Wie
  • Will
  • Wird
  • Wo
  • Woher
  • you can create a selvedge edge: You can make the edges of garter stitch more smooth by slipping the first stitch of every row.2022-02-04
  • you really only need to know two patterns: garter stitch

Recent Posts

  • What is the rising action in Julius Caesar?
  • How do you secure a rope to itself?
  • Does waterproof laminate scratch easily?
  • What makes a building prewar?
  • What can you learn in a month without alcohol?

Recent Comments

No comments to show.

Copyright © 2023 Snappy1.

Powered by PressBook Grid Dark theme