如何从广播接收器开始新活动

时间:2011-10-26 17:04:16

标签: android

我有像这样的BroadcastReceiver

    public class OnAlarmReceiver extends BroadcastReceiver {

private static final String TAG = ComponentInfo.class.getCanonicalName(); 


@Override   
public void onReceive(Context context, Intent intent) {
    Log.d(TAG, "Received wake up from alarm manager.");

    long rowid = intent.getExtras().getLong(RemindersDbAdapter.KEY_ROWID);

    WakeReminderIntentService.acquireStaticLock(context);

我想从此开始一项新活动。怎么做到呢?我尝试使用startActivty()。但这没效果。请帮忙。提前致谢

2 个答案:

答案 0 :(得分:0)

在onReceive方法中使用此代码:

Intent activityToLaunch = new Intent(context, YourActivity.class); 
Context.startActivity(intent);

答案 1 :(得分:0)

尝试这样的事情:

public class OnAlarmReceiver extends BroadcastReceiver {

  private static final String TAG = ComponentInfo.class.getCanonicalName(); 

 @Override   
 public void onReceive(Context context, Intent intent) {
 Log.d(TAG, "Received wake up from alarm manager.");r

 long rowid = intent.getExtras().getLong(RemindersDbAdapter.KEY_ROWID);

 WakeReminderIntentService.acquireStaticLock(context);

 Intent yourActivity = new Intent(getBaseContext(),your.class);
 startActivity(youActivity);