Start and close Activity:

  1. Starting Activity There
    are two situations for starting Activity:
    a) When there is only one Activity in an android application, you only need to configure it in the AndroidManifest.xml file and set it as the entry point of the program. When running the project automatically when the start the Activity
    B) when a file android, there are multiple Activity, need to be applied startActivity () method to start the required syntax Activity, startActivity () method:

public void startActivity(Intent intent)

This method has no return value, only an entry parameter of the Intent type. Intent is the communication method between the components in the Android application. An Activity expresses its own "intent" through Intent. When creating an Intent object, you need to specify that you want to be Start Activity

Example:

Intent intent = new Intent(MainActivity.this,DetailActivity.class);
startActivity(intent);
  1. Closing Activity
    If you want to close the current Activity, you can use the finish() method provided by the Activity class:
    public void finish()
    This method is relatively simple, it has neither entry parameters nor return value, and it only needs to be called in the corresponding event in the Activity This method is fine.
    If the current Activity is not the main activity, then after executing finish(), it will return to the Activity that called it, otherwise, it will return to the main screen.

Guess you like

Origin blog.csdn.net/qq_42823109/article/details/94360698