Android的意图过滤器? [英] android intent filter?
问题描述
我感觉stupid.This是很清楚,但我解决不了我的problem.So原谅我的问题。结果
我的问题是在大约intenfilter.This是我的清单文件的应用程序标记:
I'm feeling stupid.This is very clear but I can not solve my problem.So excuse me for my question.
My problem is in about intenfilter.This is application tag of my manifest file:
<application
android:icon="@drawable/ic_launcher"
android:label="@string/app_name" >
<activity
android:label="@string/app_name"
android:name=".AlakyTestActivity" >
<intent-filter >
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity
android:label="reza"
android:name=".A2" >
<intent-filter >
<action android:name="MAIN" />
<category android:name="LAUNCHER" />
</intent-filter>
</activity>
</application>
这是我的按钮点击监听器:
And this is my button click listener:
b1 = (Button)findViewById(R.id.button1);
b1.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
// TODO Auto-generated method stub
Intent intent2 = new Intent();
intent2.setAction("MAIN");
intent2.addCategory("LAUNCHER");
startActivity(intent2);
}
});
我觉得所有的东西是好的,但是当我运行我的code和点击 B1
,我得到这个erroe:
I think that all things is good but when I run my code and click on b1
,I get this erroe:
android.content.ActivityNotFoundException: No Activity found to handle Intent { act=MAIN cat=[LAUNCHER] }
修改:结果
这是A2:
Edit:
This is A2:
public class A2 extends Activity {
@Override
protected void onCreate(Bundle savedInstanceState) {
// TODO Auto-generated method stub
super.onCreate(savedInstanceState);
this.setContentView(R.layout.main2);
}
}
请帮我。
推荐答案
您应该设置了android:第二个活动的(包名)的名字(类)。
例如,可以说第二个活动类是com.my.app.reza'你应该添加您清单:
You should set the android:name of the second activity to the (package name).(the class) for example, lets say the second activity class is 'com.my.app.reza' you should add you the manifest:
<activity
android:label="@string/app_name"
android:name=".reza" >
<intent-filter >
<action android:name="com.my.app.REZA" />
<category android:name="android.intent.category.DEFUALT" />
</intent-filter>
</activity>
和你应该开始这样的活动:
and you should start the activity like that:
Intent intent = new Intent("com.my.app.REZA");
startActivity(intent);
请注意,这不是做的最好办法,你不应该乱得多带包名我建议你做以下方式:
NOTE that it isn't the best way to do it, you shouldn't mess to much with package name I'd recommend you to do it the following way:
<activity
android:label="@string/app_name"
android:name=".reza" />
和启动它这样的:
startActivity(new Intent( this.getContext() , reza.class );
这篇关于Android的意图过滤器?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!