2016-12-14 2 views
0

Hallo Ich versuche, dies zu folgen: https://technology.jana.com/2014/10/28/periodic-background-tasks-in-android/ist keine Aktivität Unterklasse oder Alias ​​

aber aus irgendeinem Grund ich erhalte: Fehler beim Ausführen der App: services.BackgroundService ist keine Aktivität Unterklasse oder Alias ​​

android Neu ...

<manifest xmlns:android="http://schemas.android.com/apk/res/android" 
package="com.mycompany.app"> 

<application 
    android:name=".Virgo"> 

    <receiver android:name="receivers.SyncReceiver"> 
     <intent-filter> 
      <action android:name="android.intent.action.BATTERY_LOW" /> 
      <action android:name="android.intent.action.BATTERY_OKAY" /> 
      <action android:name="com.mycompany.app.SYNC_TASK_HEART_BEAT" /> 
     </intent-filter> 
    </receiver> 

    <receiver android:name="receivers.BootAndUpdateReceiver"> 
     <intent-filter> 
      <action android:name="android.intent.action.MY_PACKAGE_REPLACED" /> 
      <action android:name="android.intent.action.BOOT_COMPLETED" /> 
     </intent-filter> 
    </receiver> 

    <service android:name="services.BackgroundService" /> 

</application> 

Das ist mein Service-Code wie gewünscht:

public class SyncReceiver extends BroadcastReceiver{ 
    private static final String TAG = "SyncReceiver"; 
    private static final String INTENT_ACTION = "com.rhotechnology.app.SYNC_TASK_HEART_BEAT"; 

    @Override 
public void onReceive(Context context, Intent intent) { 
     if ((intent.getAction() !=null)) { 

      Virgo virgo = (Virgo) context.getApplicationContext(); 
      SharedPreferences sharedPreferences = virgo.getSharedPreferences ("syncPreferences", android.content.Context.MODE_PRIVATE); 
      if (intent.getAction().equals("android.intent.action.BATTERY_LOW")) { 
       sharedPreferences.edit().putBoolean(Constants.BACKGROUND_SERVICE_BATTERY_CONTROL, false).apply(); 
       stopSyncReceiverHeartBeat(context); 
      } else if (intent.getAction().equals("android.intent.action.BATTERY_OKAY")) { 
       sharedPreferences.edit().putBoolean(Constants.BACKGROUND_SERVICE_BATTERY_CONTROL, true).apply(); 
       restartSyncReceiverHeartBeat(context, virgo); 
      } else if (intent.getAction().equals(INTENT_ACTION)) { 
       onSync(context, virgo); 
      } 

     } 

    } 

public void onSync(Context context, Virgo virgo){ 
    Log.v(TAG,"Syncing"); 
} 

public void restartSyncReceiverHeartBeat(Context context, Virgo virgo) { 
    SharedPreferences sharedPreferences = virgo.getSharedPreferences ("syncPreferences", MODE_PRIVATE); 
    boolean isBatteryOk = sharedPreferences.getBoolean(Constants.BACKGROUND_SERVICE_BATTERY_CONTROL, true); 
    Intent alarmIntent = new Intent(context, Virgo.class); 
    boolean isAlarmUp = PendingIntent.getBroadcast(context, 0, alarmIntent, PendingIntent.FLAG_NO_CREATE) != null; 

    if (isBatteryOk && !isAlarmUp) { 
     AlarmManager alarmManager = (AlarmManager) context.getSystemService(Context.ALARM_SERVICE); 
     alarmIntent.setAction(INTENT_ACTION); 
     PendingIntent pendingIntent = PendingIntent.getBroadcast(context, 0, alarmIntent, 0); 
     alarmManager.setInexactRepeating(AlarmManager.ELAPSED_REALTIME_WAKEUP, SystemClock.elapsedRealtime(), AlarmManager.INTERVAL_FIFTEEN_MINUTES, pendingIntent); 
    } 
} 

public void stopSyncReceiverHeartBeat(Context context) { 
    AlarmManager alarmManager = (AlarmManager) context.getSystemService(Context.ALARM_SERVICE); 
    Intent alarmIntent = new Intent(context, Virgo.class); 
    alarmIntent.setAction(INTENT_ACTION); 
    PendingIntent pendingIntent = PendingIntent.getBroadcast(context, 0, alarmIntent, 0); 
    alarmManager.cancel(pendingIntent); 
} 

}

+0

Fügen Sie Service-Code oder logcat –

+0

es kompilieren ok! aber nicht an android senden, denke ich, macht es Sinn? – Zulander

Antwort

1

Die Konfiguration im Run/Debug-Konfiguration falsch war> Start gab es eine Tätigkeit, die es gab und brachte nicht das Manifest!

Verwandte Themen