问题描述
我有活性的封装之一,我想运行一个意图从而将一个活动B,其为在包两种。
I have activity A in package one, and I want to run an intent which will up an activity B which is in package two.
我怎样才能做到这一点?所有样品将受到欢迎。
How can I do this? Any samples will be welcome.
这是香港专业教育学院做的,并且错误我得到:
this is what ive done, and the error i get:
第一个活动(MainActivity)在包:com.abelski.currencyclient而第二项活动(在不同势包SecondActivity:com.idan.second
first activity ("MainActivity") in a package: com.abelski.currencyclientand second activity("SecondActivity" in a diffrent package: com.idan.second
现在我想呼吁从MainActivity到SecondActivity。
now i wanna call from MainActivity to SecondActivity.
香港专业教育学院添加了此行的MainActivity的清单:
ive added this line at the manifest of the MainActivity:
<activity android:name="com.idan.second.SecondApplicationActivity"></activity>
现在的主要活动我得到这个按钮,运行该行:
now in main Activity i got this button which run this line:
Intent intent = new Intent(MainActivity.this,SecondApplicationActivity.class);
和这是RROR:
04-29 09:20:59.197: ERROR/AndroidRuntime(399): Uncaught handler: thread main exiting due to uncaught exception
04-29 09:20:59.276: ERROR/AndroidRuntime(399): java.lang.NoClassDefFoundError: com.idan.second.SecondApplicationActivity
04-29 09:20:59.276: ERROR/AndroidRuntime(399):
...
感谢您的帮助。
推荐答案
我假设的包你的意思是应用程序。
I am assuming that by "packages" you mean applications.
我们有: - ApplicationA与FirstActivity - ApplicationB与SecondActivity
We have:- ApplicationA with FirstActivity- ApplicationB with SecondActivity
如果在ApplicationB的AndroidManifest.xml文件,在SecondActivity的声明,你加一个意图过滤器,如:
If, in the ApplicationB's AndroidManifest.xml file, in the declaration of SecondActivity you add an intent filter such as:
<activity android:name=".SecondActivity">
<intent-filter>
<action android:name="applicationB.intent.action.Launch" />
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
</activity>
您可以创建一个Intent推出这个SecondActivity从FirstActivity有:
You can create an Intent to launch this SecondActivity from the FirstActivity with:
Intent intent = new Intent("applicationB.intent.action.Launch");
startActivity(intent);
这一切都说明是:
What this all means is:
- 的SecondActivity具有applicationB.intent.action.Launch 的意图操作的筛选器
- 当你创建与行动意图,并呼吁startActivity系统就会找到该活动(如果有的话),响应它
- The SecondActivity has a filter for the intent action of "applicationB.intent.action.Launch"
- When you create an intent with that action and call 'startActivity' the system will find the activity (if any) that responds to it
这方面的文档是:http://developer.android.com/intl/zh-TW/reference/android/content/Intent.html
这篇关于从不同的包发射活动的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!