Last active
January 25, 2023 13:16
-
-
Save hello2pal/4548094 to your computer and use it in GitHub Desktop.
How to Navigate from One Activity to Another Activity in Android
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import android.app.Activity; | |
import android.content.Intent; | |
import android.os.Bundle; | |
import android.view.View; | |
import android.view.View.OnClickListener; | |
import android.widget.Button; | |
public class MainActivity extends Activity { | |
private Button button; // | |
@Override | |
protected void onCreate(Bundle savedInstanceState) { | |
super.onCreate(savedInstanceState); | |
/* | |
*Each activity must have a corresponding layout XML file | |
*/ | |
setContentView(R.layout.activity_main);// activity_main is corresponding XML file | |
/* | |
* Initializing button XML button id. findViewById is a method which | |
* helps to initialize with particular id. btn_go_to_another_activity is | |
* a button name which I have given in XML file | |
*/ | |
button = (Button) findViewById(R.id.btn_go_to_another_activity); | |
button.setOnClickListener(new OnClickListener() { | |
@Override | |
public void onClick(View v) { | |
// TODO Auto-generated method stub | |
/* | |
* Intent is just like glue which helps to navigate one activity | |
* to another. | |
*/Intent intent = new Intent(MainActivity.this, | |
AnotherActivity.class); | |
startActivity(intent); // startActivity allow you to move | |
} | |
}); | |
} | |
} |
Noble Transfer is an online private transfer and shuttle services offering reliable, luxury and comfortable transfer services from & to the airport and tourist resorts.limousine service zurich
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
For beginners I recommend this post... https://androidride.com/how-to-move-from-one-activity-to-another-in-android/