问题
i want call project A to project B, but in project B used project C for library.
I used the code in project A
intent = new Intent("com.example.projectb.reading");
startActivity(intent);
and AndroidManifest in project B
<activity
android:name="com.example.projectb.reading"
android:label="Trainee"
android:screenOrientation="portrait">
<intent-filter>
<action android:name="com.xample.projecta.cls_show" />
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
</activity>
but i've got logcat is
08-14 15:05:24.596: E/AndroidRuntime(7835): Process: com.xample.projecta, PID: 7835
08-14 15:05:24.596: E/AndroidRuntime(7835): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.xample.projecta/com.xample.projecta.show}: android.content.res.Resources$NotFoundException: Resource ID #0x7f030033
08-14 15:05:24.596: E/AndroidRuntime(7835): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2693)
08-14 15:05:24.596: E/AndroidRuntime(7835): at android.app.ActivityThread.startActivityNow(ActivityThread.java:2435)
08-14 15:05:24.596: E/AndroidRuntime(7835): at android.app.LocalActivityManager.moveToState(LocalActivityManager.java:135)
08-14 15:05:24.596: E/AndroidRuntime(7835): at android.app.LocalActivityManager.startActivity(LocalActivityManager.java:347)
08-14 15:05:24.596: E/AndroidRuntime(7835): at android.widget.TabHost$IntentContentStrategy.getContentView(TabHost.java:776)
08-14 15:05:24.596: E/AndroidRuntime(7835): at android.widget.TabHost.setCurrentTab(TabHost.java:435)
08-14 15:05:24.596: E/AndroidRuntime(7835): at android.widget.TabHost$2.onTabSelectionChanged(TabHost.java:176)
08-14 15:05:24.596: E/AndroidRuntime(7835): at android.widget.TabWidget$TabClickListener.onClick(TabWidget.java:646)
08-14 15:05:24.596: E/AndroidRuntime(7835): at android.view.View.performClick(View.java:5184)
08-14 15:05:24.596: E/AndroidRuntime(7835): at android.view.View$PerformClick.run(View.java:20910)
08-14 15:05:24.596: E/AndroidRuntime(7835): at android.os.Handler.handleCallback(Handler.java:739)
08-14 15:05:24.596: E/AndroidRuntime(7835): at android.os.Handler.dispatchMessage(Handler.java:95)
08-14 15:05:24.596: E/AndroidRuntime(7835): at android.os.Looper.loop(Looper.java:145)
08-14 15:05:24.596: E/AndroidRuntime(7835): at android.app.ActivityThread.main(ActivityThread.java:5942)
08-14 15:05:24.596: E/AndroidRuntime(7835): at java.lang.reflect.Method.invoke(Native Method)
08-14 15:05:24.596: E/AndroidRuntime(7835): at java.lang.reflect.Method.invoke(Method.java:372)
08-14 15:05:24.596: E/AndroidRuntime(7835): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1389)
08-14 15:05:24.596: E/AndroidRuntime(7835): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1184)
08-14 15:05:24.596: E/AndroidRuntime(7835): Caused by: android.content.res.Resources$NotFoundException: Resource ID #0x7f030033
08-14 15:05:24.596: E/AndroidRuntime(7835): at android.content.res.Resources.getValue(Resources.java:2345)
08-14 15:05:24.596: E/AndroidRuntime(7835): at android.content.res.Resources.loadXmlResourceParser(Resources.java:3927)
08-14 15:05:24.596: E/AndroidRuntime(7835): at android.content.res.Resources.getLayout(Resources.java:2161)
08-14 15:05:24.596: E/AndroidRuntime(7835): at android.view.LayoutInflater.inflate(LayoutInflater.java:413)
08-14 15:05:24.596: E/AndroidRuntime(7835): at android.view.LayoutInflater.inflate(LayoutInflater.java:366)
08-14 15:05:24.596: E/AndroidRuntime(7835): at com.android.internal.policy.impl.PhoneWindow.setContentView(PhoneWindow.java:435)
08-14 15:05:24.596: E/AndroidRuntime(7835): at android.app.Activity.setContentView(Activity.java:2267)
08-14 15:05:24.596: E/AndroidRuntime(7835): at id.co.ajsmsig.eagency.Cls_training.onCreate(cls_show.java:12)
08-14 15:05:24.596: E/AndroidRuntime(7835): at android.app.Activity.performCreate(Activity.java:6289)
08-14 15:05:24.596: E/AndroidRuntime(7835): at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1119)
08-14 15:05:24.596: E/AndroidRuntime(7835): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2646)
08-14 15:05:24.596: E/AndroidRuntime(7835): ... 17 more
08-14 15:05:26.691: I/Process(7835): Sending signal. PID: 7835 SIG: 9
Please help me, where's the problem.
回答1:
Refer these two links from stackoverflow. It will help you
How to call activity of one project from activity of another project in android?Also vice versa?
2. How to call an activity in another project?
回答2:
change
intent = new Intent("com.example.projectb.reading");
startActivity(intent);
into
intent = new Intent("com.xample.projecta.cls_show");
startActivity(intent);
回答3:
you are using wrong Constructor
intent = new Intent(this, "com.example.projectb.reading");
startActivity(intent);
read intent for more information.
回答4:
You can achieve that by Intent-filter
.
FirstActivity
Intent intent = new Intent("com.example.secondapp.SecondActivity");
startActivity(intent);
SecondActivity - AndroidManifest.xml
<activity
android:name="com.example.secondapp.SecondActivity"
android:label="@string/app_name" >
<intent-filter>
<action android:name="com.example.secondapp.SecondActivity" />
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
</activity>
For more reference you can refer this.
来源:https://stackoverflow.com/questions/32005223/call-activity-from-another-project