2011-10-26 71 views
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."); 

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

    WakeReminderIntentService.acquireStaticLock(context); 

一個BroadcastReceiver我想從這個開始一個新的活動。如何做呢?我嘗試使用startActivty()。但那沒有奏效。請幫忙。在此先感謝

回答

0

使用此代碼在您的onRecieve方法:

Intent activityToLaunch = new Intent(context, YourActivity.class); 
Context.startActivity(intent); 
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); 
+0

您好,感謝您的答覆。當我嘗試這個時,我得到了一條錯誤消息來創建一個方法getbasecontext。我是android新手。請幫忙 – Matthew