您好我想更改默认活动.但是,当我这样做时,应用程序根本没有启动而没有任何错误
<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>
这样MainActivty就可以毫无问题地启动.当我按下按钮时,它也会转到设备活动.所以一切正常.
现在我需要DevcieACtivty作为默认值.
我改变了Manifest
<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>
但现在应用程序无法启动.没有错误.没有在控制台中写入.
它只是没有做任何事情,
可能有什么问题?
它开始写下面的错误
ActivityManager:开始: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:start Intent {act = android.intent.action.MAIN cat = [android.intent.category.LAUNCHER] flg =来自null的0x10000000 cmp = com.example.dimmer / .MainActivity}(pid = 13093,uid = 2000)需要null
完整的清单
<?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
解决方法:
由于您已将包定义为“com.example.dimmer”,因此可以删除包名称并仅使用活动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>
此外,请检查Eclipse中的运行配置设置.如果您的启动活动设置为MainActivity,并且在清单中将DevicesActivity设置为main,则在通过Eclipse启动时,您的应用可能无法启动.单击箭头图标,然后选择“运行配置”,
然后确保选择DevicesActivity作为Launch: