Home > Software design >  Why is the wrong activity launched in Android App despite android manifest having different value?
Why is the wrong activity launched in Android App despite android manifest having different value?

Time:07-24

I assume, there is something wrong with my AndroidManifest.xml. The relevant part is

        <activity
            android:name=".MainActivity"
            android:exported="true">
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />

                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>
        </activity>
        <activity
            android:name=".AddYActivity"
            android:exported="false" >
        </activity>
        <activity
            android:name=".AddAActivity"
            android:exported="false" >
        </activity>
        <activity
            android:name=".YOActivity"
            android:exported="false" >
        </activity>

with MainActivity.kt being

class MainActivity : AppCompatActivity() {
    private lateinit var text123: TextView
    private lateinit var YOBtn: Button
    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        setContentView(R.layout.activity_main)
        text123= findViewById(R.id.text123)

        YOBtn = findViewById(R.id.y_o_btn)
        YOBtn.setOnClickListener{
            try {
                //val yOIntent = Intent(this, YOActivity::class.java)
                //startActivity(yOIntent)
            }catch (e: Exception){
                text123.text = e.toString()
                text123.textSize = 14F
            }
        }
    }
}

addition:

I have now tried commenting everything in MainAktivity out, so it looks like this (full Main Aktivity):

package...
imports...

class MainActivity : AppCompatActivity() {
    private lateinit var appName: TextView
    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        setContentView(R.layout.activity_main)
        appName = findViewById(R.id.app_name)
    }
}

This should start with MainActivity but it does start on YOActivity.

I even commented out the section, where YOActivity is called, but no change.

addition2:

I have deletetd YOActivity in Manifest, the kotlin file and the xml with its layout. Then I did clean project, rebuilt project, make project and den run app. I also restartet the IDE and did clean rebuilt, make and run again.

It is still showing YOActivity even if it should not exist at this point.

I will start the Project again from the beginning, since i see no other solution.

CodePudding user response:

Make sure to make project successfully after your code changed. Maybe you can try to clean and rebuild your project.

CodePudding user response:

What solved the Problem was the wipe data funktion of the emulated devices in the device manager. After this, make project and run project could bring the new version to the emulation.

  • Related