For any Android Application, the Activity class is the core component. In many cases, you need to define and implement an Activity for each screen display. The Activity class needs to introduce the package import android. app. Activity.
Android applications can be multi-threaded. Android allows multiple programs to run at the same time. Applications can have background processes and can be interrupted by calls, text messages, and other events. However, at the same time, only one Activity program can be visible to users. That is to say, at any time, only one Activity of the Android application is in the foreground.
In the Android system, the system will track the running Activity objects and put these Activity objects into an Activity stack. The Activity of the current Activity is at the top of the stack. After the Activity is completed, it will be removed from the stack.
In Android, the following steps are required to switch the Activity:
1. register the Activity to AndroidMainfest. xml, for example:
<Activity
Android: name = "MessageActivity"/>
2. UI switching through Intent
Intent intent = new Intent (CurrentActivity. this, NextActivity. class );
StartActivity (intent );
Sometimes some data may need to be transferred from one Activity to another. The most common method is to use Bundle
When using the Bundle, first press the data in the current Activity into the Bundle
Intent intent = new Intent (CurrentActivity. this, NextActivity. class );
Bundle mBundle = new Bundle ();
MBundle. putString ("Data", "dataText"); // press Data
Intent. putExtras (mBundle );
StartActivity (intent );
You need to accept data after starting another Activity. The specific operations are as follows:
Bundle bundle = getIntent (). getExtras ();
String data = bundle. getString ("Data"); // read data
If you only perform interface switching, you can use another method.
You can set layout using the setContentView method. This interface is switched only in one Activity. All variables can be obtained without data being pushed and read.
Example:
SetContentView (R. layout. message );