0

10分ごとにサービスからメインのアクティビティを呼び出したいです。どうすればいいですか?

使ってみAlarmManagerました。MyAppReceiver次のコードを使用してトリガーしました。

private void setNextSchedule()
{
     AlarmManager am = (AlarmManager) getSystemService(Context.ALARM_SERVICE);
     PendingIntent pi = PendingIntent.getBroadcast(this, 0,new Intent(this,     MyAppReciever.class), 0);
     long duration = 20000;
     am.setRepeating(AlarmManager.ELAPSED_REALTIME_WAKEUP,
     SystemClock.elapsedRealtime(), duration, pi);
}

使用中と呼びましたがonStartCommand()、機能していません。

public class MyAppReciever extends BroadcastReceiver
{
    @Override
    public void onReceive(Context context, Intent intent) 
    {
        // TODO Auto-generated method stub
        Toast.makeText(context,"in myAppreceiver",Toast.LENGTH_LONG).show();
        context.startActivity(new Intent(context, MainActivity.class));
    }
}

マニフェストで

<receiver android:name=".MyAppReciever" />
4

0 に答える 0