How to navigate from one Activity screen to another Activity screen? In the first screen I\'m having one button if I click the button it has to move to another Activity scre
Button navigate;
navigate = findViewById(R.id.button);
navigate.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
Toast.makeText(getApplicationContext(),"Navigate another Activity",Toast.LENGTH_LONG).show();
Intent intent = new Intent(MainActivity.this,MainActivity2.class);
startActivity(intent);
}
});
The most trivial case (called from activity):
startActivity(new Intent(this, ActivityToLaunch.class));
More details here: http://developer.android.com/guide/topics/fundamentals.html
In your method fun onCreate(savedInstanceState: Bundle?)
add this.
your_btn_id.setOnClickListener{
val intent = Intent(this, yourpagename::class.java)
startActivity(intent)
}
Until now if it doesn't work then, check if these two files are added or not,
import android.content.Intent
import kotlinx.android.synthetic.main.activity_otp.*
startActivity(new Intent(this,newActivity.class));
final Context cont = this;
Button btnClickABC =(Button)findViewById(R.id.btnClickABC);
btnClickABC.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
startActivity(new Intent(cont, NextActivity.class));
}
});
You can navigate to the next screen using these code snippets:
Kotlin
startActivity(Intent(this, LoginActivity::class.java))
Java
startActivity(new Intent(this, LoginActivity.class))
Here's a reference: Android Developers - Starting another activity