赞
踩
1.使用 Intent 启动 不同包名 的Activity 报错:
12-19 16:22:15.341 21558-21558/com.zengjx.androidbaseproject E/AndroidRuntime: FATAL EXCEPTION: main
Process: com.zengjx.androidbaseproject, PID: 21558
android.content.ActivityNotFoundException: Unable to find explicit activity class {com.test/com.test.TestActivity}; have you declared this activity in your AndroidManifest.xml?
at android.app.Instrumentation.checkStartActivityResult(Instrumentation.java:1804)
at android.app.Instrumentation.execStartActivity(Instrumentation.java:1528)
at android.app.Activity.startActivityForResult(Activity.java:3788)
at android.support.v4.app.BaseFragmentActivityApi16.startActivityForResult(BaseFragmentActivityApi16.java:54)
at android.support.v4.app.FragmentActivity.startActivityForResult(FragmentActivity.java:67)
at android.app.Activity.startActivityForResult(Activity.java:3749)
at android.support.v4.app.FragmentActivity.startActivityForResult(FragmentActivity.java:720)
at android.app.Activity.startActivity(Activity.java:4059)
at android.app.Activity.startActivity(Activity.java:4027)
at com.zengjx.androidbaseproject.IntentActivity$1.onClick(IntentActivity.java:29)
at android.view.View.performClick(View.java:4781)
at android.view.View$PerformClick.run(View.java:19874)
at android.os.Handler.handleCallback(Handler.java:739)
at android.os.Handler.dispatchMessage(Handler.java:95)
at android.os.Looper.loop(Looper.java:135)
at android.app.ActivityThread.main(ActivityThread.java:5271)
at java.lang.reflect.Method.invoke(Native Method)
at java.lang.reflect.Method.invoke(Method.java:372)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:902)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:697)
2.被启动的Activty 在 com.test 包名下
.
主Activity:
package com.zengjx.androidbaseproject; import android.content.ComponentName; import android.content.Intent; import android.support.v7.app.AppCompatActivity; import android.os.Bundle; import android.view.View; import android.widget.Button; public class IntentActivity extends AppCompatActivity { Button btn_start; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_intent); btn_start=(Button)findViewById(R.id.btn_start); btn_start.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View view) { 同一个包名下可以启动 // ComponentName componentName=new ComponentName("com.zengjx.androidbaseproject","com.zengjx.androidbaseproject.TimerActivity"); // ComponentName componentName=new ActivityNotFoundException 不同启动失败ComponentName("com.zengjx.fragment","com.zengjx.fragment.DemoFragmentActivity"); ComponentName componentName=new ComponentName("com.test","com.test.TestActivity"); Intent intent =new Intent(); intent.setComponent(componentName); startActivity(intent); } }); } }
3.AndroidMenifest.xml :
<activity android:name="com.test.TestActivity" android:exported="true" />
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。