I want to transition screens with kotlin and java!

Introduction ...

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 ↓

To make screen transitions in each language ...

Basics of screen transition

--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

How to pass a character string at the time of screen transition

--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

How to make a screen transition by pressing a button

--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

Finally…

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

I want to transition screens with kotlin and java!
I want to make a list with kotlin and java!
I want to make a function with kotlin and java!
I want to implement various functions with kotlin and java!
I want to return to the previous screen with kotlin and java!
I want to use java8 forEach with index
I want to display images with REST Controller of Java and Spring!
I want to get along with Map [Java beginner]
I tried to interact with Java
I tried to summarize the basics of kotlin and java
Even in Java, I want to output true with a == 1 && a == 2 && a == 3
[Java] I want to test standard input & standard output with JUnit
I want to use DBViewer with Eclipse 2018-12! !!
I want to stop Java updates altogether
[Java] I want to perform distinct with the key in the object
I want to perform asynchronous processing and periodic execution with Rail !!!
I want to create a dark web SNS with Jakarta EE 8 with Java 11
I want to ForEach an array with a Lambda expression in Java
Kotlin functions and lambdas to send to Java developers
Run R from Java I want to run rJava
I tried to make Basic authentication with Java
Try to link Ruby and Java with Dapr
rsync4j --I want to touch rsync in Java.
Getting started with Kotlin to send to Java developers
I want to play with Firestore from Rails
What I did when I converted java to Kotlin
I want to be eventually even in kotlin
I want to write quickly from java to sqlite
I tried to break a block with java (1)
I want to perform aggregation processing with spring-batch
[Rails] I want to load CSS with webpacker
[Kotlin] I wanted to generate a png with a large capacity per area [Java]
Even in Java, I want to output true with a == 1 && a == 2 && a == 3 (Javassist second decoction)
I want to play a GIF image on the Andorid app (Java, Kotlin)
Even in Java, I want to output true with a == 1 && a == 2 && a == 3 (black magic edition)
I want to use Clojure's convenient functions in Kotlin
[Java] I want to calculate the difference from the date
I tried to read and output CSV with Outsystems
I tried to implement TCP / IP + BIO with JAVA
[Java 11] I tried to execute Java without compiling with javac
I want to use ES2015 in Java too! → (´ ・ ω ・ `)
I want to dark mode with the SWT app
I want to monitor a specific file with WatchService
[Java] Refer to and set private variables with reflection
If you want to use Mockito with Kotlin, use mockito-kotlin
I tried to implement Stalin sort with Java Collector
How to install Gradle and Kotlin with SDKMAN (Mac)
Let's create a TODO application in Java 2 I want to create a template with Spring Initializr and make a Hello world
I used to make nc (netcat) with JAVA normally
I want to redirect sound from Ubuntu with xrdp
I tried to create a shopping site administrator function / screen with Java and Spring
I want to return an object in CSV format with multi-line header & filter in Java
I want to implement it additionally while using kotlin on a site running Java
Java to play with Function
I want to convert characters ...
Connect to MySQL 8 with Java
Screen transition with swing, java
I tried to create a java8 development environment with Chocolatey
I tried to modernize a Java EE application with OpenShift.
How to use trained model of tensorflow2.0 with Kotlin / Java
[Java] I want to convert a byte array to a hexadecimal number