Page5.java
This code snippet shows the implementation of an Android activity named Page5, using Edge to Edge layout. It manages window insets for proper padding and defines an Intent for navigation. Perfect for understanding Activity lifecycle and layout management in Android development.package com.example.kingdom_iguiron; import android.content.Intent; import android.os.Bundle; import android.view.View; import android.widget.TextView; import androidx.activity.EdgeToEdge; import androidx.appcompat.app.AppCompatActivity; import androidx.core.graphics.Insets; import androidx.core.view.ViewCompat; import androidx.core.view.WindowInsetsCompat; public class Page5 extends AppCompatActivity { String str_charName; Intent goToPage5; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); EdgeToEdge.enable(this); setContentView(R.layout.activity_page5); ViewCompat.setOnApplyWindowInsetsListener(findViewById(R.id.main), (v, insets) -> { Insets systemBars = insets.getInsets(WindowInsetsCompat.Type.systemBars()); v.setPadding(systemBars.left, systemBars.top, systemBars.right, systemBars.bottom); return insets; }); goToPage5 = getIntent(); str_charName = goToPage5.getStringExtra("str_charName"); TextView storyTextView = findViewById(R.id.storyTextView); String story = "They sneak into the capital only to discover the kingdom’s council has labeled him the “Bringer of Ruin.” " + str_charName + " confronts the council, revealing their hypocrisy and the truth about the kingdom’s corruption. The gamer, now determined, decides to fight for the kingdom, not against it. Together, they rally a small group of allies to face the kingdom’s true enemy—a secret cabal controlling the king."; storyTextView.setText(story); } public void next(View v) { Intent goToPage6 = new Intent(this, Page6.class); goToPage6.putExtra("str_charName", str_charName); startActivity(goToPage6); } public void back(View v) { Intent goBackToPage4 = new Intent(this, Page4.class); goBackToPage4.putExtra("str_charName", str_charName); startActivity(goBackToPage4); } }
Leave a Comment