2012-03-23 12 views
0

したがって、サーバーからデータをフェッチするように繰り返しアラームを設定しています。問題は、アラームが鳴っているとは何も起こらないということです。私はそれを起動している間、エラーは表示されず、コードは正しい(私が知る限り)。Android:AlarmManagerでアラームを設定しても何も起こりませんか?

ここでアラームを設定するコードです:

private void startRequestTimer() { 

    // This is what will be called when the alarm goes off (GetOperations) 
    Intent intent = new Intent(MainActivity.this, GetOperations.class); 
    PendingIntent operation = PendingIntent.getBroadcast(MainActivity.this, 0, intent, 0); 

    // The alarm will go off in one second from now 
    long firstTime = SystemClock.elapsedRealtime(); 
    firstTime += 1000; 

    // Set the alarm 
    AlarmManager am = (AlarmManager) getSystemService(ALARM_SERVICE); 
    am.setRepeating(AlarmManager.ELAPSED_REALTIME_WAKEUP, firstTime, 5*1000, operation); 

} 

ここGetOperations.java(アラームがオフになったとき、それが呼ばれています)

package se.jbhalmstad.ndroid; 

import android.content.BroadcastReceiver; 
import android.content.Context; 
import android.content.Intent; 
import android.widget.Toast; 

public class GetOperations extends BroadcastReceiver { 

    @Override 
    public void onReceive(Context context, Intent intent) { 
     Toast.makeText(context, "Oh! The alarm went off!", 2000).show(); 
    } 

} 

とマニフェスト、場合に私は何かを台無しであるが、ここに(私は間違いがないので、私は疑いがある):

<?xml version="1.0" encoding="utf-8"?> 
<manifest xmlns:android="http://schemas.android.com/apk/res/android" 
     package="se.jbhalmstad.ndroid" 
     android:versionCode="1" 
     android:versionName="1.0"> 
    <uses-sdk android:minSdkVersion="7" /> 

    <application android:icon="@drawable/icon" android:label="@string/APP_NAME"> 

     <activity android:name=".MainActivity" 
        android:label="@string/APP_NAME"> 
      <intent-filter> 
       <action android:name="android.intent.action.MAIN" /> 
       <category android:name="android.intent.category.LAUNCHER" /> 
      </intent-filter> 
     </activity> 

     <activity android:name=".SettingsActivity" /> 
     <activity android:name=".GetOperations" /> 
    </application> 
</manifest> 

私は何かを逃したことがありますか?

答えて

1

GetOperationsをBroadcastReceiverとして宣言しましたが、マニフェストではアクティビティです。

+1

207

+0

ありがとうございました! – qwerty

関連する問題