Android app auto-start

Source: Internet
Author: User

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.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.