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.
Sign in to answer this question
It is the same account you read, post and publish with — and you will come straight back to this page.
Chintan RathodPosted Dec 16, 2011, 1:38 PM
(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
Neha TewariPosted Nov 16, 2011, 12:46 AM
Sam HobbsPosted Nov 15, 2011, 3:27 PM
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?
Karthik AgarwalPosted Nov 15, 2011, 7:06 AM
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.