BroadcastReceiver开机便运行的程序

 

 

public class BeginFromBoot extends Activity {
	private TextView mTextView01;
	public void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.begin_from_boot);
		mTextView01 = (TextView) findViewById(R.id.myTextView1);
		mTextView01.setText("开机就运行的程序");
	}
}
 

 

public class BeginFromBootReceiver extends BroadcastReceiver {
	public void onReceive(Context context, Intent intent) {
		Intent mBootIntent = new Intent(context, BeginFromBoot.class);
		/* 设定Intent开启为FLAG_ACTIVITY_NEW_TASK */
		mBootIntent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
		context.startActivity(mBootIntent);
	}
}

 manifest.xml

 

<activity
			android:name=".BeginFromBoot"
			android:label="@string/app_name">
		</activity>
		<receiver
			android:name="BeginFromBootReceiver">
			<intent-filter>
				<action
					android:name="android.intent.action.BOOT_COMPLETED" />
				<category
					android:name="android.intent.category.HOME" />
			</intent-filter>
		</receiver>
 


BroadcastReceiver开机便运行的程序