Can't start application after replacing main activity in Android

2

I renamed my MainActivity class to DataActivity and added a new main activity class with IntelliJ IDEA. I changed the AndroidManifest.xml file to the following:

 <application android:label="@string/app_name" android:icon="@drawable/icon">
        <activity android:name=".DataActivity"
                  android:screenOrientation="portrait">
        </activity>
        <activity android:name=".MainActivity" android:screenOrientation="portrait"
                  android:label="@string/app_name">
            <intent-filter>
                <action android:name="android.intent.action.MAIN"/>
                <category android:name="android.intent.category.LAUNCHER"/>
            </intent-filter>
        </activity>
</application>

I uninstalled the app from my phone and deleted the compiler cache. At install, I get the following exception:

Launching application: com.example.DataTest/com.example.DataTest.DataActivity.

DEVICE SHELL COMMAND: am start -n "com.example.DataTest/com.example.DataTest.DataActivity" -a android.intent.action.MAIN -c android.intent.category.LAUNCHER java.lang.SecurityException: Permission Denial: starting Intent { act=android.intent.action.MAIN cat=[android.intent.category.LAUNCHER] flg=0x10000000 cmp=com.example.DataTest/.DataActivity } from null (pid=5882, uid=2000) requires null

What else should I do?

android
intellij-idea
android-activity
asked on Stack Overflow Jan 18, 2014 by Nestor • edited Dec 11, 2020 by Nestor

2 Answers

2

This post helped me where to look. In the comments, zeh claims that the SDK holds a refence to the original activity. I checked the launch configuration, and in my IDEA it has been altered from "Launch default activity" to "Launch activity: DataActivity". It works now okay.

answered on Stack Overflow Jan 18, 2014 by Nestor • edited May 23, 2017 by Community
0

Change it to this to include the intent filters with your new main activity:

<activity android:name=".DataActivity"
          android:screenOrientation="portrait">
    <intent-filter>
        <action android:name="android.intent.action.MAIN"/>
        <category android:name="android.intent.category.LAUNCHER"/>
    </intent-filter>
</activity>
<activity android:name=".MainActivity" android:screenOrientation="portrait"
          android:label="@string/app_name">
</activity>

and remove "MainActivity" if it no longer exists. i.e. delete this:

<activity android:name=".MainActivity" android:screenOrientation="portrait"
          android:label="@string/app_name">
</activity>
answered on Stack Overflow Jan 18, 2014 by Jim

User contributions licensed under CC BY-SA 3.0