How can Android achieve multiple page navigation?

There are several ways to achieve page navigation between multiple screens in Android.

  1. To use Intent: Create an Intent object in the current Activity and specify the target Activity to navigate to. Then, use the startActivity method to launch the new Activity. You can also use the putExtra method to pass data to the target Activity.
Intent intent = new Intent(CurrentActivity.this, TargetActivity.class);
intent.putExtra("key", value);
startActivity(intent);
  1. Use explicit Intent: specify the name of the target Activity you want to navigate to (including the package name).
Intent intent = new Intent();
intent.setClassName("com.example.app", "com.example.app.TargetActivity");
startActivity(intent);
  1. Using implicit intents: By specifying the action and data type of the intent, the system will find a matching activity to handle the transition.
Intent intent = new Intent();
intent.setAction(Intent.ACTION_VIEW);
intent.setData(Uri.parse("http://www.example.com"));
startActivity(intent);
  1. Use startActivityForResult: In the current Activity, call the startActivityForResult method to start a new Activity and set the result in the target Activity. Then, override the onActivityResult method in the current Activity to retrieve the result.
Intent intent = new Intent(CurrentActivity.this, TargetActivity.class);
startActivityForResult(intent, requestCode);

These are common ways to navigate between multiple pages, the specific method to use depends on your needs and scenario.

bannerAds