1

I'm a novice Android programmer, and to help me understand how Intents really work, I wanted to put together a small Activity which would let the user call startActivity() with any action and data they want. I tried many different combinations, including "android.intent.action.VIEW" and "http://www.google.com". No matter what combinations I use, I always get an ActivityNotFoundException. Any ideas as to why?

The code in my only Activity is below:

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);
        }
    }
}

The results of adb shell logcat from the time of starting the app to just after touching 'Force close' are below.

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}

2 Answers 2

2

I tried many different combinations, including "android.intents.action.VIEW" and "html://www.google.com".

android.intents.action.VIEW is not a valid activity action. You probably want to drop the s.

html://www.google.com is not a valid URL. You probably want to replace the html:// with http://.

5
  • And...that's what happens when you don't proofread. Thanks for pointing that out, but I actually used the correct forms in the application. Still doesn't work.
    – Mrrvomun
    Aug 9, 2010 at 1:09
  • @Mrrvomun: Delete all references to Builder (you don't need it) and just put the typed-in text into the Intent. Aug 9, 2010 at 1:28
  • You mean for the data parameter? Eclipse gives me an error, and I can't find a constructor that is passed two strings. The setData method requires a Uri object, too.
    – Mrrvomun
    Aug 9, 2010 at 2:23
  • @Mrrvomun: Uri.parse() converts a String into a Uri. Aug 9, 2010 at 11:52
  • Problem solved! I think Uri.Builder was converting the colon after http into the ampersand code. Thanks so much!
    – Mrrvomun
    Aug 9, 2010 at 13:26
1

Check your logs with:

adb shell logcat

But I guess you are missing the definition of your Activity in your AndroidManifest.xml

1
  • The main and only Activity is in the AndroidManifest.xml file. I'm working in Eclipse, so I'm pretty sure that isn't screwed up.
    – Mrrvomun
    Aug 9, 2010 at 1:11

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.