从另一个项目调用活动

时间:2015-08-14 08:07:52

标签: android class android-intent android-activity project

我希望将项目A调用到项目B,但是在项目B中,将项目C用于库。

我使用了项目A中的代码

intent = new Intent("com.example.projectb.reading");
        startActivity(intent);
项目B中的

和AndroidManifest

<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>

但是我的logcat已经

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

请帮助我,问题在哪里。

4 个答案:

答案 0 :(得分:1)

答案 1 :(得分:1)

变化

   intent = new Intent("com.example.projectb.reading");
    startActivity(intent);

    intent = new Intent("com.xample.projecta.cls_show");
    startActivity(intent);

答案 2 :(得分:0)

您使用的是错误的构造函数

intent = new Intent(this, "com.example.projectb.reading");
        startActivity(intent);

阅读intent了解详情。

答案 3 :(得分:0)

您可以通过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>    

有关详情,请参阅this.