import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
public class StartupReceiver extends BroadcastReceiver
{
@Override
public void onReceive(Context context, Intent intent)
{
// 启动一个Service
Intent serviceIntent = new Intent(context, MyService.class);
context.startService(serviceIntent);
// 启动一个Activity
Intent activityIntent = new Intent(context, MessageActivity.class);
// 要想在Service中启动Activity,必须设置如下标志
activityIntent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
context.startActivity(activityIntent);
}
}
不要忘 了,要在manifest里配置receiver和service