Sunday, 23 April 2023

How To Kill Activity onClick Button? #AndroidStudio #Java

 To Kill (Or Finish) An Activity On A Button Click, You Can Use The finish() Method In The Button's onClickListener. Here's An Example:



Button closeButton = findViewById(R.id.close_button); closeButton.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { finish(); // This will finish the current activity and remove it from the stack } });


In This Example, Close_Button Is The Id Of The Button That Will Be Used To Close The Activity. When The Button Is Clicked, The finish() Method Will Be Called Which Will Finish The Current Activity And Remove It From The Activity Stack.

No comments:

Post a Comment

What is Java Permutation and Combination Program?

Here's A Java Program That Calculates Permutations And Combinations: ```Java Import Java.Util.Scanner; Public Class Permutationcombinati...