Screen transition by [Android Studio] [Java] button

I will leave it as my own memo.

Required files (4 in total)

・MainActivity.java ・ Activity_main.xml ・SubActivity.java ・ Activity_sub.xml

Source code of MainActivity.java

Added lines 17-24

スクリーンショット 2020-01-31 21.56.09.png
Button nextButton = findViewById(R.id.bt_next);
nextButton.setOnClickListener(new View.OnClickListener() {
    @Override
    public void onClick(View v) {
        Intent intent = new Intent(getApplication(),SubActivity.class);
        startActivity(intent);
    }
});

Source code of SubActivity.java

Added lines 16-22

スクリーンショット 2020-01-31 21.56.46.png
Button backButton = findViewById(R.id.bt_back);
backButton.setOnClickListener(new View.OnClickListener() {
    @Override
    public void onClick(View v) {
        finish();
    }
});

activity.xml (design tab)

Pay attention to the id at the top right of the screen!

スクリーンショット 2020-01-31 21.57.19.png

activity_sub.xml (design tab)

Pay attention to the id at the top right of the screen!

スクリーンショット 2020-01-31 21.57.29.png

Recommended Posts

Screen transition by [Android Studio] [Java] button
Screen transition by Post method [Java]
[Java Swing] Screen transition by CardLayout
[Android / Java] Screen transition and return processing in fragments
Android development ~ Screen transition (intent) ~
[Android Studio] [Java] How to fix the screen vertically
Screen transition with swing, java
[Android Studio] [Java] Learning memos & links
[Java] Button template class by Graphics
Reintroducing Java 8 available from Android Studio 2.4
Android Studio x Wear Os by Google
[Android / Java] Switch events by display Fragment
Java to C and C to Java in Android Studio
Screen transition method
Screen transition memorandum
JavaFX8 screen transition
[Java] 4 steps to implement splash screen on Android
[Android 9.0 Pie Java] LINE-style chat list screen → personal chat screen transition animation implemented (with sample application)
[Android Studio] How to change TextView to any font [Java]
[Android / Java] Set up a button to return to Fragment
Notes in Android studio
Defeating Android Studio Part 3-6
Defeating Android Studio Part 1 & Part 2
[Android] Exit the activity of the transition source at the time of screen transition
Refer to C ++ in the Android Studio module (Java / kotlin)
Use Java included with Android Studio to build React Native
You are currently using Java 6. Solution in Android Studio Gradle