StartService when tab focused

This commit is contained in:
tom79 2017-09-26 19:35:02 +02:00
parent 1909522b3d
commit b0a4681a04
3 changed files with 27 additions and 2 deletions

View File

@ -328,6 +328,17 @@ public class MainActivity extends AppCompatActivity
toot.setVisibility(View.GONE);
DrawerLayout drawer = (DrawerLayout) findViewById(R.id.drawer_layout);
drawer.closeDrawer(GravityCompat.START);
if( tab.getPosition() == 2 && !display_local && display_global){
streamingFederatedIntent = new Intent(getApplicationContext(), StreamingFederatedTimelineService.class);
startService(streamingFederatedIntent);
}else if( tab.getPosition() == 3 && display_local && display_global){
streamingFederatedIntent = new Intent(getApplicationContext(), StreamingFederatedTimelineService.class);
startService(streamingFederatedIntent);
}else{
if( streamingFederatedIntent != null)
stopService(streamingFederatedIntent);
}
}
@Override

View File

@ -73,6 +73,11 @@ public class StreamingFederatedTimelineService extends IntentService {
public void onCreate() {
super.onCreate();
SharedPreferences sharedpreferences = getSharedPreferences(Helper.APP_PREFS, Context.MODE_PRIVATE);
boolean display_global = sharedpreferences.getBoolean(Helper.SET_DISPLAY_GLOBAL, true);
if( !display_global){
stopSelf();
}
}

View File

@ -211,8 +211,6 @@ public class MainActivity extends AppCompatActivity
streamingIntent = new Intent(this, StreamingService.class);
startService(streamingIntent);
streamingFederatedIntent = new Intent(this, StreamingFederatedTimelineService.class);
startService(streamingFederatedIntent);
if( !broadCastRegistred) {
LocalBroadcastManager.getInstance(this).registerReceiver(receive_data, new IntentFilter(Helper.RECEIVE_DATA));
@ -331,6 +329,17 @@ public class MainActivity extends AppCompatActivity
toot.setVisibility(View.GONE);
DrawerLayout drawer = (DrawerLayout) findViewById(R.id.drawer_layout);
drawer.closeDrawer(GravityCompat.START);
if( tab.getPosition() == 2 && !display_local && display_global){
streamingFederatedIntent = new Intent(getApplicationContext(), StreamingFederatedTimelineService.class);
startService(streamingFederatedIntent);
}else if( tab.getPosition() == 3 && display_local && display_global){
streamingFederatedIntent = new Intent(getApplicationContext(), StreamingFederatedTimelineService.class);
startService(streamingFederatedIntent);
}else{
if( streamingFederatedIntent != null)
stopService(streamingFederatedIntent);
}
}
@Override