In this Android example, a small program is implemented. The special feature of this program is that it runs only once and then runs independently with the startup of the mobile phone.
First, we need to add the following code in the AndroidManifest. xml file to capture mobile phone startup events:
<! -- Delegate the handler name to the alias -->
<Cycler android: name = "HippoStartupIntentReceiver">
<! -- Set BOOT_COMPLETED in the filter to the information to be captured -->
<Intent-filter>
<Action android: name = "android. intent. action. BOOT_COMPLETED"/>
<Category android: name = "android. intent. category. HOME"/>
</Intent-filter>
</Cycler>
Where:
Android. intent. action. BOOT_COMPLETED
This line of code is used to receive broadcast events sent by the system.
The complete code of this program is given below:
1. Main program code
This Code actually provides an Activity UI and is not responsible for receiving system broadcasts.
Public class EX06_16 extends Activity
{
/* The program only needs to run once? Automatically run after startup */
Private TextView mTextView01;
/** Called when the activity is first created .*/
@ Override
Public void onCreate (Bundle savedInstanceState)
{
Super. onCreate (savedInstanceState );
SetContentView (R. layout. main );
/* For quick illustration, the program uses only the welcome TextView text for demonstration */
MTextView01 = (TextView) findViewById (R. id. myTextView1 );
MTextView01.setText (R. string. str_welcome );
}
}
2. Broadcast Receiver
Public class EX06_16 extends Activity
{
/* The program only needs to run once? Automatically run after startup */
Private TextView mTextView01;
/** Called when the activity is first created .*/
@ Override
Public void onCreate (Bundle savedInstanceState)
{
Super. onCreate (savedInstanceState );
SetContentView (R. layout. main );
/* For quick illustration, the program uses only the welcome TextView text for demonstration */
MTextView01 = (TextView) findViewById (R. id. myTextView1 );
MTextView01.setText (R. string. str_welcome );
}
}
Android content:
- When Android is deprecated, the Activity repeats. solution:
- Add a number to the icon in Android
- Modify TitleBar layout for Android
- The R file of Android cannot be generated.