1

I have a very simple application (an example from a textbook) that consists of 2 activities: The first activity UsingIntentActivity has a button. When this button is clicked it must lead to the second activity called SecondActivity which will show a text on the screen.

I can achieve this using startActivity(new Intent(this, SecondActivity.class));

However in the textbook where I met this example another form of the same method is used:

startActivity(new Intent("net.dreamingpixel.SecondActivity")); 

And in the Manifest File a matching custom intent is created (as I understood):

 <activity android:name=".UsingIntentActivity" android:label="@string/title_activity_using_intent" > <intent-filter> <action android:name="android.intent.action.MAIN" /> <category android:name="android.intent.category.LAUNCHER" /> </intent-filter> </activity> <activity android:name=".SecondActivity" android:label="Second Activity" > <intent-filter> <action android:name="net.dreamingpixel.SecondActivity" /> <category android:name="android.intent.category.DEFAULT" /> </intent-filter> </activity> 

So there is an intent-filter and its category is set to DEFAULT. But when I try to run the app like this and click the button of the UsingIntentActivity the app crashes. In the log cat I can see the following messages:

FATAL EXCEPTION: main java.lang.IllegalStateException: Could not execute the method of the activity 

And then it points to the call of the startActivity method that I wrote at the beginning of this post.

Did anyone have a similar problem? Did I make a mistake somewhere?

UPDATE: Also I noticed that there is a warning in the Manifest file on the line where I open the second activity tag. It says: Exported activity does not require permission

Maybe this warning has to do something with my problem..

4
  • 1
    Did you name your package "net.dreamingpixel"? Commented Jul 15, 2012 at 9:35
  • The package's name is "net.dreamingpixel.usingintent". Is that wrong? Commented Jul 15, 2012 at 9:40
  • Yes, you should name it "net.dreamingpixel" or change your call to startActivity(new Intent("net.dreamingpixel.usingintent.SecondActivity")); Commented Jul 15, 2012 at 10:57
  • I have already tried it. It didn't help.. Commented Jul 15, 2012 at 11:30

1 Answer 1

1

As you send that you have created second activity in manifest file as per

startActivity(new Intent("net.dreamingpixel.SecondActivity")); 

Here net.dreamingpixel.SecondActivity means, here you need to provide the activity name with the package you created in your project...

In manifest at the top you will find package name. You need to use that package name with your activity...

Here as per above code..

 net.dreamingpixel ----- is a package SecondActivity ----- is an Activity in that package. 
Sign up to request clarification or add additional context in comments.

7 Comments

no, that is just an intent filter, you could write any String in there as long as you write the same string in the manifest's intent filter too
I updated the intent's name to net.dreamingpixel.usingintent as @ofir-a. suggested, but that didn't solve my problem. The Android documentation says: "Create an intent with a given action. All other fields (data, type, class) are null. Note that the action must be in a namespace because Intents are used globally in the system -- for example the system VIEW action is android.intent.action.VIEW; an application's custom action would be something like com.google.app.myapp.CUSTOM_ACTION."
otherwise do one thing.. as you are writing intent in startActivity(new intent("....")), change that one to Intent it = new Intent ("net.dreamingpixel.SecondActivity"); startActivity(it); It will be silly because both of them are same but some times it works.
@Limbo Wanderer I want to correct myself. When you use intent filter, all you need is to write the same in your manifest file and in your intent call. So if you write the next thing 'startActivity(new Intent("dreamingpixel.SecondActivity"));' and in the manifest you write '<action android:name="dreamingpixel.SecondActivity" />' it should work. Other then that I don't know what's the exact problem here.
@code_finder Thanks for the help, but no, that didn't work either.. Maybe I should create a new emulator and try there? Any other ideas?
|

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.