Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Changing default activity in android

hello I want to change default activity. But when I do that the app doesn't launch at all without any errors

<activity 
        android:name="com.example.dimmer.MainActivity"
        android:label="@string/app_name">
        <intent-filter>
            <action android:name="android.intent.action.MAIN" />
            <category android:name="android.intent.category.LAUNCHER" />
        </intent-filter>
    </activity>

    <activity
        android:name="com.example.dimmer.DevicesActivity" >
    </activity>

This way MainActivty launches with no proble. It also goes to Device activity when I press the button. So everything works fine. Now I need DevcieACtivty to be default one.

I change Manifest like that

<activity 
            android:name="com.example.dimmer.DevicesActivity"
            android:label="@string/app_name">
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />
                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>
        </activity>

        <activity
            android:name="com.example.dimmer.MainActivity" >
        </activity>

but now app doesn't launch. no errors. nothing is written in console. it's just doesn't do anything, what might be a problem?

It starts to write the following error ActivityManager: Starting: Intent { act=android.intent.action.MAIN cat=[android.intent.category.LAUNCHER] cmp=com.example.dimmer/.MainActivity } [2014-05-16 21:17:10 - Dimmer] ActivityManager: java.lang.SecurityException: Permission Denial: starting Intent { act=android.intent.action.MAIN cat=[android.intent.category.LAUNCHER] flg=0x10000000 cmp=com.example.dimmer/.MainActivity } from null (pid=13093, uid=2000) requires null

full Manifest

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    package="com.example.dimmer"
    android:versionCode="1"
    android:versionName="1.0" 
    android:hardwareAccelerated="false">

    <uses-sdk
        android:minSdkVersion="9"
        android:targetSdkVersion="14" />
    <uses-permission android:name="android.permission.INTERNET" /> 

    <application
        android:allowBackup="true"
        android:icon="@drawable/ic_launcher"
        android:label="@string/app_name"
        android:theme="@style/AppTheme" >

        <activity 
            android:name="com.example.dimmer.DevicesActivity"
            android:label="@string/app_name">
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />
                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>
        </activity>

        <activity
            android:name="com.example.dimmer.MainActivity" >
        </activity>

    </application>

</manifest>


[2014-05-16 22:13:25 - Dimmer] Android Launch!
[2014-05-16 22:13:25 - Dimmer] adb is running normally.
[2014-05-16 22:13:25 - Dimmer] Performing com.example.dimmer.MainActivity activity launch
[2014-05-16 22:13:26 - Dimmer] Uploading Dimmer.apk onto device 'SH17VT514235'
[2014-05-16 22:13:26 - Dimmer] Installing Dimmer.apk...
[2014-05-16 22:13:29 - Dimmer] Success!
[2014-05-16 22:13:29 - Dimmer] Starting activity com.example.dimmer.MainActivity on device SH17VT514235
[2014-05-16 22:13:29 - Dimmer] ActivityManager: Starting: Intent { act=android.intent.action.MAIN cat=[android.intent.category.LAUNCHER] cmp=com.example.dimmer/.MainActivity }
[2014-05-16 22:13:29 - Dimmer] ActivityManager: java.lang.SecurityException: Permission Denial: starting Intent { act=android.intent.action.MAIN cat=[android.intent.category.LAUNCHER] flg=0x10000000 cmp=com.example.dimmer/.MainActivity } from null (pid=15458, uid=2000) requires null
like image 319
user3485986 Avatar asked Mar 19 '23 14:03

user3485986


1 Answers

Since you've defined your package as "com.example.dimmer", you can remove package name and use just the name of Activity with dot in front:

<application
    android:allowBackup="true"
    android:icon="@drawable/ic_launcher"
    android:label="@string/app_name"
    android:theme="@style/AppTheme" >

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

    <activity
        android:name=".MainActivity" >
    </activity>

</application>

Moreover, check your Run configuration settings in Eclipse. If your launching activity was set to MainActivity, and in manifest you make DevicesActivity as main, your app might not start when launching via Eclipse. Click arrow for RUN icon and choose "Run Configurations",

enter image description here

Then make sure you choose DevicesActivity as Launch:

enter image description here

like image 122
Melquiades Avatar answered Mar 28 '23 22:03

Melquiades