Get the App
SLTechnology News&Howtos  ›  Development  › 

How to implement Android Application component Activity

Shulou Source: shulou.com Published: 2022-06-02 06:08:01 10月15日 Update

This article focuses on "how to implement Android application component Activity". Interested friends may wish to have a look at it. The method introduced in this paper is simple, fast and practical. Let's let the editor take you to learn how to implement the Android application component Activity.

The default Activity for the application is defined in the src/shy/luo/task/MainActivity.java file.

Its implementation is very simple.

When one of the buttons above it is clicked, another Actvity named "shy.luo.task.subactivity" is launched.

The Actvity implementation named "shy.luo.task.subactivity" is in the src/shy/luo/task/SubActivity.java file:

[java] view plaincopypackage shy.luo.task; import android.app.Activity; import android.os.Bundle; import android.util.Log; import android.view.View; import android.view.View.OnClickListener; import android.widget.Button; public class SubActivity extends Activity implements OnClickListener {private final static String LOG_TAG = "shy.luo.task.SubActivity"; private Button finishButton = null; @ Override public void onCreate (Bundle savedInstanceState) {super.onCreate (savedInstanceState); setContentView (R.layout.sub); finishButton = (Button) findViewById (R.id.button_finish) FinishButton.setOnClickListener (this); Log.i (LOG_TAG, "Sub Activity Created.");} @ Override public void onClick (View v) {if (v.equals (finishButton)) {finish ();}

Its implementation is also very simple, when you click on an ammonium button above, you will end yourself and go back to the previous Activity.

Let's take a look at the application's configuration file AndroidManifest.xml:

[html] view plaincopypackage= "shy.luo.task"

Android:versionCode= "1"

Android:versionName= "1.0" > android:label=" @ string/app_name "> android:label=" @ string/sub_activity "

Android:launchMode= "singleTask" >

At this point, I believe you have a deeper understanding of "how to implement the Android application component Activity". You might as well do it in practice. Here is the website, more related content can enter the relevant channels to inquire, follow us, continue to learn!

Tags: Application program application component file content name time face learning practical deeper interest practical practical button easy to operate method more friends Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno macOS Redmi Linux MariaDB Docker