• After 15+ years, we've made a big change: Android Forums is now Early Bird Club. Learn more here.

Apps Stumped by Intents

I am sorry, this is probably a very basic question, but my first Android program keeps getting hung when trying to switch to another activity. I have gone through several tutorials and the documentation, and I am starting to think that I am either leaving something basic out, or I am mixing methods too much. Hopefully someone can spot the problem, and show me where I am messing up.

So far, the app consists of two classes, Index and Statistics. Index is the default class, and gives the user a list of options. Statistics goes to the web, downloads an XML file of data, and displays it to the user. Both extend Activity and use onCreate and appear to work on their own.

In the manifest, I have defined a custom action for the Statistics activity:
Code:
<activity
	android:name="Statistics"
	android:label="@string/stats_title">
	<intent-filter>
		<action android:name="com.package.project.action.SHOW_STATISTICS" />
	</intent-filter>
</activity>

In the index class, I have a method that receives a button click and tries to start the Activity by creating a new Intent:
Code:
if (R.id.statsButton == v.getId()) {
	// The user wants to view the statistics, create an Intent
	try {
		startActivity(new Intent("com.package.project.action.SHOW_STATISTICS"));
	} catch (ActivityNotFoundException e) {
		showDialog(DIALOG_TESTING);
	}
}

When this code runs, the test dialog is displayed, indicating an ActivityNotFoundException occurred. Is there somewhere else that com.package.project.activity.SHOW_STATISTICS needs to be declared for example?

Any thoughts?

Thanks in advance for reading, and any suggestions/guidance you can offer.
 
regulatre, yes, I added it to the manifest using the code in the first snippet. Does the syntax look correct?

Dave, thanks, I will try adding the category. I ended up using the setClass method, since I think that is probably more appropriate in this instance, but as the application becomes more complex, being able to use an implicit Intent will probably become necessary, so I hope to be able to get it working. I will try the category and post back with the results.
 
Upvote 0

BEST TECH IN 2023

We've been tracking upcoming products and ranking the best tech since 2007. Thanks for trusting our opinion: we get rewarded through affiliate links that earn us a commission and we invite you to learn more about us.

Smartphones