How to shift within two Activities in an Android

Assume there is an android application and in the “src” folder there are two Activities named as “RedFlashlightActivity”  and “GreenFlaslightActivity”. When the application run first start the “RedFlashlightActivity”. We can assure that by putting <intent-filter> tag in that particular Activity in the Manifest file as follows.

<activity android:name=".RedFlashlightActivity" android:label="@string/app_name">

<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />

Because we have mentioned about the Manifest file there is one more thing that we have to remember when we dealing with multiple Activities. That is after we create a new Activity we have to manualy enter that Activity in to the Manifest file like bellow.

<activity android:name=".GreenFlaslightActivity"> </activity>

Assue there is a Button item in “RedFlashlightActivity” and when the user click on it, should shift to the “GreenFlaslightActivity”. We have to write that code under the onClick event as follows.

greenButton.setOnClickListener(new View.OnClickListener() {
public void onClick(View arg0) {

Intent intent = new Intent(RedFlashlightActivity.this, GreenFlaslightActivity.class); startActivity(intent);

In here we have used inner class concept rather than implementing the relevant interface.
Now you can shift with in those two Activities and further more you can use default “Back” key of the phone to go back to the previous Activity.
Thank you🙂

About AnujAroshA

An undergraduate in the stream of ICT (Information & Communication Technology). A simple person :)
This entry was posted in Android Examples. Bookmark the permalink.

One Response to How to shift within two Activities in an Android

  1. Dianna says:

    I’m thankful to get a call from a friend as he identified the key suggestions shared on your site.
    Exploring your blog post is a real excellent experience.
    Thank you for taking into consideration readers like me,
    and I wish you the best.

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s