我是Android新手程序员,为了帮助我理解Intent的工作原理,我想组建一个小型Activity,让用户可以使用他们想要的任何动作和数据调用startActivity()。我尝试了很多不同的组合,包括“android.intent.action.VIEW”和“http://www.google.com”。无论我使用什么组合,我总是得到一个ActivityNotFoundException。关于为什么的任何想法?
我唯一的活动中的代码如下:
public class TestingIntents extends Activity
{
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
Button goButton = (Button) findViewById(R.id.button);
goButton.setOnClickListener(new ClickListener());
}
private class ClickListener implements OnClickListener
{
@Override
public void onClick(View arg0)
{
String id = ((EditText) findViewById(R.id.intent)).getText().toString();
String data = ((EditText) findViewById(R.id.data)).getText().toString();
Builder builder = new Builder();
builder = builder.path(data);
Uri path = builder.build();
Intent i = new Intent(id, path);
startActivity(i);
}
}
}
从启动应用程序到触摸'强制关闭'之后的adb shell logcat的结果如下所示。
I/ActivityManager( 1086):
Starting activity: Intent { act=android.intent.action.
MAIN cat=[android.intent.category.LAUNCHER] flg=0x10200000 cmp=tk.h2g2guy.testin
gIntents/.TestingIntents }
I/ActivityManager( 1086): Start proc tk.h2g2guy.testingIntents for activity tk.h
2g2guy.testingIntents/.TestingIntents: pid=4037 uid=10054 gids={}
D/dalvikvm( 1006): GC_EXPLICIT freed 289 objects / 10960 bytes in 98ms
D/dalvikvm( 1006): GC_EXPLICIT freed 47 objects / 2088 bytes in 121ms
D/dalvikvm( 1006): GC_EXPLICIT freed 2 objects / 48 bytes in 109ms
I/ActivityManager( 1086): Displayed activity tk.h2g2guy.testingIntents/.TestingI
ntents: 462 ms (total 462 ms)
D/dalvikvm( 2300): GC_EXPLICIT freed 1226 objects / 61640 bytes in 69ms
I/ActivityManager( 1086): Starting activity: Intent { act=android.intent.action.
VIEW dat=http%3A//www.google.com }
D/AndroidRuntime( 4037): Shutting down VM
W/dalvikvm( 4037): threadid=1: thread exiting with uncaught exception (group=0x4
001d7e0)
E/AndroidRuntime( 4037): FATAL EXCEPTION: main
E/AndroidRuntime( 4037): android.content.ActivityNotFoundException: No Activity
found to handle Intent { act=android.intent.action.VIEW dat=http%3A//www.google.
com }
E/AndroidRuntime( 4037): at android.app.Instrumentation.checkStartActivit
yResult(Instrumentation.java:1408)
E/AndroidRuntime( 4037): at android.app.Instrumentation.execStartActivity
(Instrumentation.java:1378)
E/AndroidRuntime( 4037): at android.app.Activity.startActivityForResult(A
ctivity.java:2817)
E/AndroidRuntime( 4037): at android.app.Activity.startActivity(Activity.j
ava:2923)
E/AndroidRuntime( 4037): at tk.h2g2guy.testingIntents.TestingIntents$Clic
kListener.onClick(TestingIntents.java:41)
E/AndroidRuntime( 4037): at android.view.View.performClick(View.java:2408
)
E/AndroidRuntime( 4037): at android.view.View$PerformClick.run(View.java:
8816)
E/AndroidRuntime( 4037): at android.os.Handler.handleCallback(Handler.jav
a:587)
E/AndroidRuntime( 4037): at android.os.Handler.dispatchMessage(Handler.ja
va:92)
E/AndroidRuntime( 4037): at android.os.Looper.loop(Looper.java:123)
E/AndroidRuntime( 4037): at android.app.ActivityThread.main(ActivityThrea
d.java:4627)
E/AndroidRuntime( 4037): at java.lang.reflect.Method.invokeNative(Native
Method)
E/AndroidRuntime( 4037): at java.lang.reflect.Method.invoke(Method.java:5
21)
E/AndroidRuntime( 4037): at com.android.internal.os.ZygoteInit$MethodAndA
rgsCaller.run(ZygoteInit.java:868)
E/AndroidRuntime( 4037): at com.android.internal.os.ZygoteInit.main(Zygot
eInit.java:626)
E/AndroidRuntime( 4037): at dalvik.system.NativeStart.main(Native Method)
W/ActivityManager( 1086): Force finishing activity tk.h2g2guy.testingIntents/.
TestingIntents
W/ActivityManager( 1086): Activity pause timeout for HistoryRecord{449d4518 tk.h
2g2guy.testingIntents/.TestingIntents}
I/Process ( 4037): Sending signal. PID: 4037 SIG: 9
I/ActivityManager( 1086): Process tk.h2g2guy.testingIntents (pid 4037) has died.
I/WindowManager( 1086): WIN DEATH: Window{44bd4120 tk.h2g2guy.testingIntents/tk.
h2g2guy.testingIntents.TestingIntents paused=false}
答案 0 :(得分:2)
我尝试了很多不同的组合, 包含 “android.intents.action.VIEW”和 “HTML://www.google.com”。
android.intents.action.VIEW
不是有效的活动操作。您可能想放弃s
。
html://www.google.com
不是有效的网址。您可能希望将html://
替换为http://
。
答案 1 :(得分:1)
使用以下方法检查您的日志:
adb shell logcat
但我猜您错过了Activity
AndroidManifest.xml
的定义