This article was written in 4 previous articles,
** 5th day of article posting every day for 7 days **
It has become
I'll put the code to use below, but see the article four before for the detailed features of this app!
--java version: https://github.com/sato-na/guruwake_java
--kotlin version: https://github.com/sato-na/guruwake_kotlin
↓ This is the main subject of this article ↓
--For java
Intent intent = new intent(Pre-transition activity.this,Post-transition activity.class);
startActivity(intent);
Example)
MainActivity.java
Intent intent = new Intent(MainActivity.this, WhoActivity.class); //25th line
startActivity(intent);
--For kotlin
val intent = Intent(application,Post-transition activity::class.java)
startActivity(intent)
Example)
MainActivity.kt
val intent = Intent(application, WhoActivity::class.java) //18th line
startActivity(intent)
The intent setting method is very different
--For java
(Activity before transition)
Intent intent = new Intent(Current activity.this,Next activity.class);
intent.putExtra("Key associated with the value",Value you want to pass);
startActivity(intent);
Example)
HowManyActivity.java
String groupNum = groupNumE.getText().toString(); //Line 43
Intent intent = new Intent(WhoActivity.this, HowManyActivity.class); //Line 46
intent.putExtra("GROUP_NUM", groupNum); //Send groupNum to CheckActivity//Line 48
startActivity(intent);
(Activity after transition)
Intent intent = getIntent();
final String variable name= intent.getStringExtra("Key associated with the value");
Example)
CheckActivity.java
Intent intent = getIntent(); //25th line
final String groupNum = intent.getStringExtra("GROUP_NUM"); //27th line
--For kotlin
(Activity before transition)
val intent = Intent(application,Post-transition activity::class.java)
intent.putExtra("Key associated with the value",Value you want to pass)
startActivity(intent)
Example)
HowManyActivity.kt
val groupNum = group_num_et.text.toString() //Line 33
val intent = Intent(application, CheckActivity::class.java) //36th line
intent.putExtra("GROUP_NUM", groupNum) //Send groupNum to CheckActivity//38th line
startActivity(intent)
(Activity after transition)
val variable name= intent.getStringExtra("Key associated with the value")
Example)
CheckActivity.kt
val groupNum = intent.getStringExtra("GROUP_NUM")
The code to receive the value to write in the activity after the transition is different
--For java
Button variable name= findViewById(R.id.Button id);
variable.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
//Screen transition
}
});
Example)
MainActivity.java
Button startButton = findViewById(R.id.start_btn); //Line 19
startButton.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
Intent intent = new Intent(MainActivity.this, WhoActivity.class);
startActivity(intent);
}
});
--For kotlin
Button id.setOnClickListener {
//Screen transition
}
Example)
MainActivity.kt
start_btn.setOnClickListener { //16th line
val intent = Intent(application, WhoActivity::class.java)
startActivity(intent)
}
Overall, kotlin requires less code than java when dealing with buttons
This time, I pressed the button with java and kotlin to change the screen. Overall, I had the impression that kotlin was easier to write than java.
I will post an article tomorrow, so please keep an eye on me.
Recommended Posts