Fixes an issue when killing service when app went in background

This commit is contained in:
tom79 2017-09-30 08:29:39 +02:00
parent 02e52334b6
commit 0f773d3d7b
5 changed files with 7 additions and 1 deletions

View File

@ -926,6 +926,7 @@ public class MainActivity extends AppCompatActivity
SharedPreferences.Editor editor = sharedpreferences.edit();
String userId = sharedpreferences.getString(Helper.PREF_KEY_ID, null);
editor.putBoolean(Helper.SHOULD_CONTINUE_STREAMING_FEDERATED+userId, false);
stopService(streamingIntent);
editor.apply();
}
if( receive_data != null)

View File

@ -385,6 +385,7 @@ public class DisplayStatusFragment extends Fragment implements OnRetrieveFeedsIn
public void onResume(){
super.onResume();
if( type == RetrieveFeedsAsyncTask.Type.PUBLIC){
if( getUserVisibleHint() ){
SharedPreferences sharedpreferences = context.getSharedPreferences(Helper.APP_PREFS, Context.MODE_PRIVATE);
SharedPreferences.Editor editor = sharedpreferences.edit();
@ -452,6 +453,7 @@ public class DisplayStatusFragment extends Fragment implements OnRetrieveFeedsIn
String userId = sharedpreferences.getString(Helper.PREF_KEY_ID, null);
editor.putBoolean(Helper.SHOULD_CONTINUE_STREAMING_FEDERATED+userId, false);
editor.apply();
context.stopService(streamingFederatedIntent);
}
}
}
@ -466,6 +468,7 @@ public class DisplayStatusFragment extends Fragment implements OnRetrieveFeedsIn
String userId = sharedpreferences.getString(Helper.PREF_KEY_ID, null);
editor.putBoolean(Helper.SHOULD_CONTINUE_STREAMING_FEDERATED+userId, false);
editor.apply();
context.stopService(streamingFederatedIntent);
}
}

View File

@ -23,6 +23,7 @@ import android.os.Bundle;
import android.os.SystemClock;
import android.support.annotation.Nullable;
import android.support.v4.content.LocalBroadcastManager;
import android.util.Log;
import org.json.JSONException;

View File

@ -22,6 +22,7 @@ import android.os.Bundle;
import android.os.SystemClock;
import android.support.annotation.Nullable;
import android.support.v4.content.LocalBroadcastManager;
import android.util.Log;
import org.json.JSONException;
@ -118,7 +119,6 @@ public class StreamingService extends IntentService {
String event;
EventStreaming eventStreaming;
while((event = reader.readLine()) != null) {
if( !sharedpreferences.getBoolean(Helper.SHOULD_CONTINUE_STREAMING + accountStream.getId(), true) )
stopSelf();
if ((lastEvent == EventStreaming.NONE || lastEvent == null) && !event.startsWith("data: ")) {

View File

@ -929,6 +929,7 @@ public class MainActivity extends AppCompatActivity
SharedPreferences.Editor editor = sharedpreferences.edit();
String userId = sharedpreferences.getString(Helper.PREF_KEY_ID, null);
editor.putBoolean(Helper.SHOULD_CONTINUE_STREAMING_FEDERATED+userId, false);
stopService(streamingIntent);
editor.apply();
}
if( receive_data != null)