Because a small project requires the development of Android APP, I am here to learn Android. At the same time, I have not touched JAVA, so I don't have a deep understanding of various grammars for the time being. Only a record of how to use it is convenient for copying and pasting.
Reference learning video: 30 hours of Android Android development to get Baidu map from scratch (2020 Android development full set of tutorials)
The event of the corresponding button:
public void sendMessage(View view){
EditText msg = findViewById(R.id.message);
String s = msg.getText().toString();
//页面切换
写法一:class跳转
Intent intent = new Intent(this,secondActivity.class);
this.startActivity(intent);
写法二:包名.类名
// Intent intent = new Intent();
// intent.setClassName(this,"cn.edu.cdut.mainactivity.secondActivity");
// startActivity(intent);
//这个写法不知道为什么点击之后软件会崩溃,暂不作细究
写法三:ComponentName
// Intent intent = new Intent();
// ComponentName cname= new ComponentName(this,secondActivity.class);
// intent.setComponent(cname);
// startActivity(intent);
隐式启动:写法一
// Intent intent = new Intent();
// intent.setAction("action.nextActivity");
// startActivity(intent);
写法二:
Intent intent = new Intent("action.nextActivity");
startActivity(intent);
}
注:action.nextActivity为 xml文件中自定义的action名字
The part of AndroidManifest.xml file is:
<activity android:name=".secondActivity">
<intent-filter>
<action android:name="action.nextActivity" />
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
</activity>
The category defaults to LAUNCHER, which will generate a new APP icon