1
0
Fork 0
mirror of https://github.com/syncthing/syncthing-android.git synced 2024-11-30 00:01:19 +00:00

Fixed service stopping on Activity exit.

This commit is contained in:
Felix Ableitner 2014-05-13 17:59:52 +02:00
parent 745de67005
commit 11f3c46fa0
2 changed files with 8 additions and 0 deletions

View file

@ -28,6 +28,11 @@ public class SyncthingService extends Service {
private final SyncthingServiceBinder mBinder = new SyncthingServiceBinder(this); private final SyncthingServiceBinder mBinder = new SyncthingServiceBinder(this);
@Override
public int onStartCommand(Intent intent, int flags, int startId) {
return START_STICKY;
}
/** /**
* Creates notification, starts native binary. * Creates notification, starts native binary.
*/ */
@ -41,6 +46,7 @@ public class SyncthingService extends Service {
.setSmallIcon(R.drawable.ic_launcher) .setSmallIcon(R.drawable.ic_launcher)
.setContentIntent(pi) .setContentIntent(pi)
.build(); .build();
n.flags |= Notification.FLAG_ONGOING_EVENT;
startForeground(NOTIFICATION_ID, n); startForeground(NOTIFICATION_ID, n);
new Thread(new Runnable() { new Thread(new Runnable() {

View file

@ -94,6 +94,8 @@ public class WebGuiActivity extends Activity {
@Override @Override
public void onCreate(Bundle savedInstanceState) { public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState); super.onCreate(savedInstanceState);
getApplicationContext().startService(
new Intent(this, SyncthingService.class));
getApplicationContext().bindService( getApplicationContext().bindService(
new Intent(this, SyncthingService.class), new Intent(this, SyncthingService.class),
mSyncthingServiceConnection, Context.BIND_AUTO_CREATE); mSyncthingServiceConnection, Context.BIND_AUTO_CREATE);