Skip to content

Instantly share code, notes, and snippets.

@hello2pal
Last active January 25, 2023 13:16
Show Gist options
  • Save hello2pal/4548094 to your computer and use it in GitHub Desktop.
Save hello2pal/4548094 to your computer and use it in GitHub Desktop.
How to Navigate from One Activity to Another Activity in Android
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
}
});
}
}
Copy link

ghost commented Jan 13, 2020

@chaufferservicezurich
Copy link

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