Launching a New Activity by Class Name

You can start activities in several ways.The simplest method is to use the Application Context object to call the startActivity() method, which takes a single parameter, an Intent.

An Intent (android.content.Intent) is an asynchronous message mechanism used by the Android operating system to match task requests with the appropriate Activity or Service (launching it, if necessary) and to dispatch broadcast Intents events to the system at large.

For now, though, we focus on Intents and how they are used with Activities.The following line of code calls the startActivity() method with an explicit Intent.This Intent requests the launch of the target Activity named MyDrawActivity by its class. This class is implemented elsewhere within the package.

startActivity(new Intent(getApplicationContext(), MyDrawActivity.class));

This line of code might be sufficient for some applications, which simply transition from one Activity to the next. However, you can use the Intent mechanism in a much more robust manner. For example, you can use the Intent structure to pass data between Activities.

Was this article helpful?

0 0
Easy Software Profits

Easy Software Profits

Here's How Anyone Can Start, Build and Run their Own Successful Software Empire Without Knowing the First Thing About Programming, Scripting Or Any 'Coder' Stuff. There is no doubt about it software sells. Software has a high percieved value and it solves problems for people.  A claim that can't always be made for PDF books, Video products and the like.

Get My Free Ebook

Post a comment