0

i have a very simple app, an activity with only a button to open another activity

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

    val btnAct2 = findViewById<Button>(R.id.btnAct2)
    btnAct2.setOnClickListener{
        val i = Intent(this,SecondActivity::class.java)
        startActivity(i)
    }
}

and the Second activity is just empty

class SecondActivity : AppCompatActivity() {
override fun onCreate(savedInstanceState:Bundle?) {
    super.onCreate(savedInstanceState)
    setContentView(R.layout.activity_second)
}

when opening the second activity, log always show a warning, but the activity start normally. Why is this warning?

W/ActivityThread: handleWindowVisibility: no activity for token android.os.BinderProxy@xxxxxx

I search everywhere, but all answers are for activities that doesnt start and app crash, or context does not exist. Tried update android studio, rebuild proyect, invalidate cache like some post sugests, without success.

Abelucho
  • 220
  • 1
  • 9
  • Your code is fine, maybe this is a broken system code. Have you tried running the same code on another device? Preferably of another manufacturer. – Shlomi Katriel Jan 07 '23 at 18:18
  • Tried on 3 differents (Motorola, Samsung and LG) and like 3 emulators... same result. – Abelucho Jan 07 '23 at 18:57
  • Saw a post somewhere that a person had the exact same error and it disappeared after they copied the project code into a new project (So I guess you should not worry about that?) – JustSightseeing Jan 07 '23 at 19:05
  • Checkout this: https://stackoverflow.com/questions/63448563/cancel-acitivity-handlewindowvisibility-no-activity-for-token. maybe you call `finish()` multiple times. (can be debugged by overriding `finish()` and printing stack trace/breakpoint) – Shlomi Katriel Jan 08 '23 at 06:33

1 Answers1

0

This is just a Warning as hinted by the W/ presuffix on the log. This relates to the Android OS itself and not your App Package. It doesn't prevent your app from running.

Your Question says the second activity is being launched as expected:

when opening the second activity, log always show a warning, but the activity start normally. Why is this warning?

There are multiple processes running on the emulators apart from your app and they show different warning/debug/errors/info messages on the LogCat in relation to the background processes depending on the SDK

These warnings should be ignored, and you should only be worried if your app really crashes.

In case of a crash you should filter out the errors by applying level:error filter on your LogCat to see the details of the error. Alternatively, you can use say tag:SecondActivity filter on your LogCat together with Timber or the normal Log Class to see exactly what is happening to your app in particular.

Tonnie
  • 4,865
  • 3
  • 34
  • 50