Hello Friends,,
I have just started working upon android, could any one please tell me how to call a activity inside another activity on the click event of a button.
Loading
Know the answer? Post it. Somebody with the same question will find it here.
Answer a question in the forums and earn +20 SHARP for every answer.
See unanswered questions
DevSocialUpcoming · 3rd editionAI Agents ConferenceDec 1–3, 2026Live onlineFree to attend5days leftRegister
Karthik AgarwalRank #2,270 · 620 reputationPosted Nov 15, 2011, 2:06 AM EST
http://developer.android.com/guide/topics/fundamentals.html
In the above link look for sub heading "Application Components" and then "Activities", there it is explained in detail.
Sam HobbsRank #107 · 20.5K reputationPosted Nov 15, 2011, 10:27 AM EST
I have just begun learning about Android, so I cannot help.
Is the activity to be called in your application or an application that was developed by someone else?
Neha Tewari19 reputationPosted Nov 15, 2011, 7:46 PM EST
Chintan RathodRank #516 · 4.8K reputationPosted Dec 16, 2011, 8:38 AM EST
(1) Write This code in main source file... make some changes as per your application name and package name. Before writing this code, make sure that you have Button in layout having id as "button1"
Code:
package com.intentapp;
import android.app.Activity;
import android.content.Intent;
import android.view.View;
import android.widget.Button;
public class IntentAppActivity extends Activity {
/** Called when the activity is first created. */
Button btnNext;
@Override
public void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
btnNext = (Button)findViewById(R.id.button1);
btnNext.setOnClickListener(new View.onClickListener(){
public void onClick(View v)
{
Intent i = new Intent(IntentAppActivity.this,IntentA.class);
startActivity(i);
}
});
}
(2) Create layout file in layout folder. to do this, click on project, right click on it, select new from it, find "Android XML" and name "newlayout.xml" and choose "layout" as type.
Following is code for layout. Path "layout/intenta_layout.xml"
Code:
android:layout_width="fill_parent"
android:layout_height="fill_parent"
/>
(3) Create "IntentA.java" file in package.
Code:
package com.intentapp;
import android.app.Activity;
import android.view.View;
import android.widget.Toast;
public class IntentA extends Activity {
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.intenta_layout);
Toast.makeText(this, "Hi!!!", 1000).show();
}
}
(4) And you have to register your activity in "manifest.xml" file by following code
Note: code will be between