Commit aa91bb6f by Simhachalam ch

changed service to Job Service to avoid crash in android 8.0 versions

parent 708eda49
......@@ -36,7 +36,7 @@ android {
defaultConfig {
applicationId "com.vsoft.vera"
minSdkVersion 21
minSdkVersion 23
targetSdkVersion 28
versionCode 1
versionName "0.0.1"
......@@ -72,7 +72,7 @@ android {
vportal {
applicationId "com.vsoft.vera.vportal"
versionCode 1
versionName "1.1.0"
versionName "0.2.1"
}
}
}
......
......@@ -88,7 +88,8 @@
android:screenOrientation="portrait" />
<activity android:name=".ui.InAppWebViewActivity" />
<service android:name=".service.SyncService" />
<service android:name=".service.SyncService"
android:permission="android.permission.BIND_JOB_SERVICE" />
<provider
android:name="android.support.v4.content.FileProvider"
......
package com.vsoft.vera;
import android.app.job.JobInfo;
import android.app.job.JobScheduler;
import android.content.BroadcastReceiver;
import android.content.ComponentName;
import android.content.Context;
import android.content.Intent;
import android.content.IntentFilter;
......@@ -45,10 +48,11 @@ public class CatalogueApplication extends MultiDexApplication {
String action = intent.getStringExtra(Constants.APPLICATION_BROADCAST_DATA_ACTION);
Log.d(Constants.TAG, "CatalogueApplication: onReceive: action: " + action);
if (Constants.ACTION_SYNC.equals(action)) {
Intent syncMatchSummaryIntentIntent = new Intent(context, SyncService.class);
//Intent syncMatchSummaryIntentIntent = new Intent(context, SyncService.class);
if (Constants.DEBUG)
Log.d(Constants.TAG, "CatalogueApplication: Start SyncService");
context.startService(syncMatchSummaryIntentIntent);
//context.startService(syncMatchSummaryIntentIntent);
scheduleJob(context);
}
}
};
......@@ -75,6 +79,20 @@ public class CatalogueApplication extends MultiDexApplication {
}
};
// schedule the start of the service every 10 - 30 seconds
public static void scheduleJob(Context context) {
ComponentName serviceComponent = new ComponentName(context, SyncService.class);
JobInfo.Builder builder = new JobInfo.Builder(0, serviceComponent);
builder.setMinimumLatency(1 * 1000); // wait at least
builder.setOverrideDeadline(3 * 1000); // maximum delay
//builder.setRequiredNetworkType(JobInfo.NETWORK_TYPE_UNMETERED); // require unmetered network
//builder.setRequiresDeviceIdle(true); // device should be idle
//builder.setRequiresCharging(false); // we don't care if the device is charging or not
JobScheduler jobScheduler = context.getSystemService(JobScheduler.class);
jobScheduler.schedule(builder.build());
}
@Override
public void onCreate() {
super.onCreate();
......
package com.vsoft.vera.service;
import android.app.IntentService;
import android.app.job.JobParameters;
import android.app.job.JobService;
import android.content.Intent;
import android.os.AsyncTask;
import com.vsoft.vera.CatalogueApplication;
import com.vsoft.vera.api.listeners.get.GetChatServerApiListener;
......@@ -62,29 +65,45 @@ import static com.vsoft.vera.db.managers.CatalogueItemInputManager.getDirtyItemI
*/
public class SyncService extends IntentService {
public class SyncService extends JobService {
private SyncStatus syncStatus = SyncStatus.FAIL;
public SyncService() {
super(SyncService.class.getSimpleName());
@Override
public boolean onStartJob(JobParameters params) {
BackgroundQueueAsync backgroundQueueAsync = new BackgroundQueueAsync();
backgroundQueueAsync.execute();
return false;
}
@Override
protected void onHandleIntent(Intent intent) {
CatalogueApplication application = (CatalogueApplication) getApplication();
if (!application.isNetConnected()) {
CatalogueLog.e("SyncService: onHandleIntent(): Not connected to net. Exit.");
return;
public boolean onStopJob(JobParameters params) {
return false;
}
public class BackgroundQueueAsync extends AsyncTask<Void, Void, Void> {
public BackgroundQueueAsync() {
}
if(Util.isChatItemEnabled()) {
if (application.getSocket() == null) {
getChatServerUrl();
@Override
protected Void doInBackground(Void... voids) {
CatalogueApplication application = (CatalogueApplication) getApplication();
if (!application.isNetConnected()) {
CatalogueLog.e("SyncService: onHandleIntent(): Not connected to net. Exit.");
}else{
if(Util.isChatItemEnabled()) {
if (application.getSocket() == null) {
getChatServerUrl();
}
}
startSync();
}
}
startSync();
return null;
}
}
/**
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or sign in to comment