Zero-based Android Studio-based Android Development Study Notes No. 2 Interface Jump

I was not going to write a separate log for the page jump, because the segue in ios development simply creates a new View Controller, and then segues to the new page (View Controller) in the jump button of the current page. ; I didn't expect that when I realized it in Android Studio, I found that the two are not the same, so I have this note.

6. Page Jump

Reference blog

There are two ways: the first is. MainActivity jump; the second is the Relaylayout layout jump

Here is only the first way to learn: MainActiviey jump

specific process:

  1. In the onCreate method of the current MainActivity: get the button control instance, register the listener for the jump button bt_skip, implement the listener interface, write the event, and use the intent to jump;
//获得(跳转)按钮实例
Button button = findViewById(R.id.bt_skip);
//按钮进行监听
button.setOnClickListener(new View.OnClickListener() {
    
    
    @Override
    public void onClick(View v) {
    
    
        //监听按钮,如果点击,就跳转
        Intent intent = new Intent();
        //前一个(MainActivity.this)是目前页面,后面一个是要跳转的下一个页面
        intent.setClass(MainActivity.this,myPageActivity.class);
        startActivity(intent);
    }
});
  1. Need to add the entry of the second page in the AndroidManifest.xml configuration
<activity android:name=".myPageActivity"/>

The activity element in the application element in the activity element manifest element: declares an Activity that implements the application visual interface, which is a necessary child element of the element. All activities must be represented by elements in the manifest file (AndroidManifest.xml). Any activity not declared here is invisible to the system and will never be executed.

  1. Create a new page java class file myPageActivity.java under com.example.myapplication
 public class myPageActivity extends AppCompatActivity {
    
    
    @Override
    protected void onCreate(Bundle savedInstanceState) {
    
    
        super.onCreate(savedInstanceState);
        //利用布局资源文件设置用户界面
        setContentView(R.layout.my_page);
    }
}

This class and MainActivity need to extend AppCompatActivity, and override the onCreate method, and set the user interface in the onCreate method (the layout file is my_page.xml under /layout)

7. Attributes in the Manifest element

About the AndroidManifest.xml file:
Insert picture description hereInsert picture description here

8.intent

Android provides an Intent mechanism to assist in the interaction and communication between applications. Intent is responsible for describing the action of an operation in the application, the data involved in the action, and additional data. According to the description of this Intent, Android is responsible for finding the corresponding component and setting the Intent Pass to the calling component, and complete the component call. Intent can be used not only between applications, but also for interaction between Activity/Service within the application. Therefore, Intent plays a role of a media intermediary here, specifically providing information related to the mutual invocation of components, and realizing the decoupling between the caller and the callee.

Guess you like

Origin blog.csdn.net/weixin_56336619/article/details/115037846