您的位置:首页 > 其它

【求助】使用intent-filter跳转activity出错

2014-10-22 00:00 253 查看
============问题描述============

/*

Intent intent=new Intent();

intent.setClass(MainActivity.this, Activity02.class);

intent.setData(Uri.parse("Hello"));

this.startActivity(intent);

*/

Intent intent=new Intent("com.example.app08.Activity02" );

intent.setData(Uri.parse("Hello"));

startActivity(intent);

我使用注释里面的代码可以正常打开新的activity,而用其下面的那一段程序就会崩溃,我想不出是什么原因,大家帮忙分析一下。

manifest.xml如下:

<?xml version="1.0" encoding="utf-8"?>

<manifest xmlns:android="http://schemas.android.com/apk/res/android"

package="com.example.app08"

android:versionCode="1"

android:versionName="1.0" >

<uses-sdk

android:minSdkVersion="8"

android:targetSdkVersion="14" />

<application

android:allowBackup="true"

android:icon="@drawable/ic_launcher"

android:label="@string/app_name"

android:theme="@style/AppTheme" >

<activity

android:name="com.example.app08.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.app08.Activity02"

android:label="@string/Activity02"

android:theme="@android:style/Theme.Dialog">

<intent-filter>

<action android:name="com.example.app08.Activity02" />

<category android:name="android.intent.category.DEFAULT" />

</intent-filter>

</activity>

</application>

</manifest>

============解决方案1============

Intent intent=new Intent("com.example.app08.Activity02" );

这里的com.example.app08.Activity02是action参数,你都没指定class怎么跳转啊

============解决方案2============

你可以这样写,Intent intent=new Intent(MainActivity.this, Activity02.class );

============解决方案3============

引用 4 楼 DR_TITI 的回复:
Quote: 引用 1 楼 sagittarius1988 的回复:

Intent intent=new Intent("com.example.app08.Activity02" );

这里的com.example.app08.Activity02是action参数,你都没指定class怎么跳转啊


后面的代码是我在书上看到的,试了不行,我以为代码是正确的,是我自己哪里写错了。

就按你能用的方法写就行了
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: