我们如何从android中的应用程序启动其他应用程序?目前我正在使用以下代码,但它在logcat中显示错误。请检查我的代码和错误消息,请提供一些建议。
sample code
package com.example.testintent;
import android.app.Activity;
import android.content.ComponentName;
import android.content.Intent;
import android.os.Bundle;
import android.view.Menu;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
public class MainActivity extends Activity implements OnClickListener {
Button b1;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
b1=(Button)findViewById(R.id.button1);
b1.setOnClickListener(this);
}
@Override
public void onClick(View v) {
Intent intent = new Intent("android.intent.action.MAIN");
ComponentName component = new ComponentName("com.abcd.main", "com.abcd.main.SplashScreenActivity");
intent.setComponent(component );
startActivity(intent);
}
}
logcat错误
03-29 15:17:06.857: W/dalvikvm(5051): threadid=1: thread exiting with uncaught exception (group=0x40c601f8)
03-29 15:17:06.862: E/AndroidRuntime(5051): FATAL EXCEPTION: main
03-29 15:17:06.862: E/AndroidRuntime(5051): android.content.ActivityNotFoundException: Unable to find explicit activity class {com.abcd.main/com.abcd.main.SplashScreenActivity}; have you declared this activity in your AndroidManifest.xml?
03-29 15:17:06.862: E/AndroidRuntime(5051): at android.app.Instrumentation.checkStartActivityResult(Instrumentation.java:1511)
03-29 15:17:06.862: E/AndroidRuntime(5051): at android.app.Instrumentation.execStartActivity(Instrumentation.java:1387)
03-29 15:17:06.862: E/AndroidRuntime(5051): at android.app.Activity.startActivityForResult(Activity.java:3195)
03-29 15:17:06.862: E/AndroidRuntime(5051): at android.app.Activity.startActivity(Activity.java:3302)
03-29 15:17:06.862: E/AndroidRuntime(5051): at com.example.testintent.MainActivity.onClick(MainActivity.java:31)
03-29 15:17:06.862: E/AndroidRuntime(5051): at android.view.View.performClick(View.java:3627)
03-29 15:17:06.862: E/AndroidRuntime(5051): at android.view.View$PerformClick.run(View.java:14329)
03-29 15:17:06.862: E/AndroidRuntime(5051): at android.os.Handler.handleCallback(Handler.java:605)
03-29 15:17:06.862: E/AndroidRuntime(5051): at android.os.Handler.dispatchMessage(Handler.java:92)
03-29 15:17:06.862: E/AndroidRuntime(5051): at android.os.Looper.loop(Looper.java:137)
03-29 15:17:06.862: E/AndroidRuntime(5051): at android.app.ActivityThread.main(ActivityThread.java:4511)
03-29 15:17:06.862: E/AndroidRuntime(5051): at java.lang.reflect.Method.invokeNative(Native Method)
03-29 15:17:06.862: E/AndroidRuntime(5051): at java.lang.reflect.Method.invoke(Method.java:511)
03-29 15:17:06.862: E/AndroidRuntime(5051): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:980)
03-29 15:17:06.862: E/AndroidRuntime(5051): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:747)
03-29 15:17:06.862: E/AndroidRuntime(5051): at dalvik.system.NativeStart.main(Native Method)
答案 0 :(得分:0)
我们如何从android中的应用程序启动其他应用程序?
在有效的导出活动上调用startActivity()
。
它显示了logcat中的错误
com.abcd.main.SplashScreenActivity
应用中的 com.abcd.main
不是有效的导出活动。