Saturday, February 23, 2008

Opening New Screen

SDK Version : 0.9-r1

This code allows calling other classes from a class (or opening a new screen). Useful for starting a new Activity like a new screen or dialog.



try
{
Intent i = new Intent(<this classname>.this, <class to be called>.class);
startActivity(i); // startSubActivity(i,0) will also work if you just want to open a dialog box.
}
catch (ActivityNotFoundException e)
{
showAlert("Error", "Activity not found", "OK", false);
}


Intent takes two parameters,

1. The current context of the package.

2. Class to be called.

You also need to declare the new class in the "AndroidManifest.xml" file. Following is a template code :

<activity name=".Classname" label="@string/title">
<intent-filter>
<!--– any permissions you want to assign to the new Class–-->
</intent-filter>
</activity>

No comments: