如何调用正确运行几个类(intents)?
问题描述:
我是Java Android开发人员的初学者。我正在使用Eclipse SDK 3.6.1版本。我试图做这件事情:在第一类(布局 - main.xml)是按钮“hello”,它调用新类(布局 - second.xml),在这个类中按钮“hello2”,它calss新类。当我按下第一个按钮“hello”时,我无法做到这一点,因为我收到这条消息“应用程序(xxxx)意外停止,请再试一次”。如何解决这个问题。我认为问题是在AndroidManifest.xml:如何调用正确运行几个类(intents)?
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="net.kodinis_raktas"
android:versionCode="1"
android:versionName="1.0">
<application android:icon="@drawable/icon" android:label="@string/app_name">
<activity android:name=".veiksmas"
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=".second" >
<intent-filter>
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
</activity>
<activity android:name=".lock"></activity>
<intent-filter>
</intent-filter>
</application>
<uses-permission android:name="android.permission.SEND_SMS">
</uses-permission>
<uses-permission android:name="android.permission.RECEIVE_SMS">
</uses-permission>
<uses-sdk android:minSdkVersion="3" />
</manifest>
答
使用adb logcat
,DDMS,或在Eclipse中DDMS角度来考察logcat的,看看你的错误相关的堆栈跟踪。这会给你更多的信息。
我建议从.second
和.lock
中删除<intent-filter>
元素,因为您没有使用它们。如果您的错误来自于尝试启动.second
,您的类别<intent-filter>
的存在可能会阻止该活动的启动。
答
在我与Android,我认为你需要后activity android:name=".second"
android:label="@string/app_name">