Android 8.0 - Job Intent Service does not run application on bootup












0















Initially I had Android 7.0 and didn't have any issues using a BroadcastReceiver and service. However with changes to Android 8.0. I needed to switch to a JobIntentService so my application can run on bootup.



I have tried migrating my code to match the JobIntentService but nothing is happening on bootup.
I am unsure whether the reason is because of my service class or my BroadcastReceiver class.



AndroidManifest.xml



    <service android:name=".backgroundService"
android:permission="android.permission.BIND_JOB_SERVICE"/>


backgroundService.java



    public class backgroundService extends JobIntentService {

public static final int JOB_ID = 0x01;

public static void enqueueWork(Context context, Intent work) {
enqueueWork(context, backgroundService.class, JOB_ID, work);
}


@Override
protected void onHandleWork(@NonNull Intent intent) {

Toast.makeText(this, "Application and Service Started", Toast.LENGTH_LONG).show();
Intent dialogIntent = new Intent(this, Home.class);
dialogIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
startActivity(dialogIntent);
}
}


startOnBoot.java



    public class startOnBoot extends BroadcastReceiver {
@Override
public void onReceive(Context context, Intent intent) {
if (intent.getAction() != null && intent.getAction().equals(Intent.ACTION_BOOT_COMPLETED)) {
Log.i("In" , "getAction() - Boot");
backgroundService.enqueueWork(context, intent);
}
else
Log.i("No" , "Boot");
}
}


So I am trying to essentially start the Home.class on bootup.










share|improve this question

























  • Take a loot at stackoverflow.com/questions/6391902/…

    – Rockey
    Jan 2 at 14:44











  • This doesn't help because with android 8.0 you cannot use implicit broadcast receivers so I am trying to use a job intent service. The link doesn't provide any sort of help?

    – godlypython
    Jan 2 at 14:47











  • I think ACTION_BOOT_COMPLETED is still accepted on Android 8 stackoverflow.com/questions/45981888/…

    – Rockey
    Jan 2 at 14:52













  • Well..I have included this in my manifest as well. Still no luck. Not sure what the issue is.

    – godlypython
    Jan 2 at 15:07
















0















Initially I had Android 7.0 and didn't have any issues using a BroadcastReceiver and service. However with changes to Android 8.0. I needed to switch to a JobIntentService so my application can run on bootup.



I have tried migrating my code to match the JobIntentService but nothing is happening on bootup.
I am unsure whether the reason is because of my service class or my BroadcastReceiver class.



AndroidManifest.xml



    <service android:name=".backgroundService"
android:permission="android.permission.BIND_JOB_SERVICE"/>


backgroundService.java



    public class backgroundService extends JobIntentService {

public static final int JOB_ID = 0x01;

public static void enqueueWork(Context context, Intent work) {
enqueueWork(context, backgroundService.class, JOB_ID, work);
}


@Override
protected void onHandleWork(@NonNull Intent intent) {

Toast.makeText(this, "Application and Service Started", Toast.LENGTH_LONG).show();
Intent dialogIntent = new Intent(this, Home.class);
dialogIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
startActivity(dialogIntent);
}
}


startOnBoot.java



    public class startOnBoot extends BroadcastReceiver {
@Override
public void onReceive(Context context, Intent intent) {
if (intent.getAction() != null && intent.getAction().equals(Intent.ACTION_BOOT_COMPLETED)) {
Log.i("In" , "getAction() - Boot");
backgroundService.enqueueWork(context, intent);
}
else
Log.i("No" , "Boot");
}
}


So I am trying to essentially start the Home.class on bootup.










share|improve this question

























  • Take a loot at stackoverflow.com/questions/6391902/…

    – Rockey
    Jan 2 at 14:44











  • This doesn't help because with android 8.0 you cannot use implicit broadcast receivers so I am trying to use a job intent service. The link doesn't provide any sort of help?

    – godlypython
    Jan 2 at 14:47











  • I think ACTION_BOOT_COMPLETED is still accepted on Android 8 stackoverflow.com/questions/45981888/…

    – Rockey
    Jan 2 at 14:52













  • Well..I have included this in my manifest as well. Still no luck. Not sure what the issue is.

    – godlypython
    Jan 2 at 15:07














0












0








0








Initially I had Android 7.0 and didn't have any issues using a BroadcastReceiver and service. However with changes to Android 8.0. I needed to switch to a JobIntentService so my application can run on bootup.



I have tried migrating my code to match the JobIntentService but nothing is happening on bootup.
I am unsure whether the reason is because of my service class or my BroadcastReceiver class.



AndroidManifest.xml



    <service android:name=".backgroundService"
android:permission="android.permission.BIND_JOB_SERVICE"/>


backgroundService.java



    public class backgroundService extends JobIntentService {

public static final int JOB_ID = 0x01;

public static void enqueueWork(Context context, Intent work) {
enqueueWork(context, backgroundService.class, JOB_ID, work);
}


@Override
protected void onHandleWork(@NonNull Intent intent) {

Toast.makeText(this, "Application and Service Started", Toast.LENGTH_LONG).show();
Intent dialogIntent = new Intent(this, Home.class);
dialogIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
startActivity(dialogIntent);
}
}


startOnBoot.java



    public class startOnBoot extends BroadcastReceiver {
@Override
public void onReceive(Context context, Intent intent) {
if (intent.getAction() != null && intent.getAction().equals(Intent.ACTION_BOOT_COMPLETED)) {
Log.i("In" , "getAction() - Boot");
backgroundService.enqueueWork(context, intent);
}
else
Log.i("No" , "Boot");
}
}


So I am trying to essentially start the Home.class on bootup.










share|improve this question
















Initially I had Android 7.0 and didn't have any issues using a BroadcastReceiver and service. However with changes to Android 8.0. I needed to switch to a JobIntentService so my application can run on bootup.



I have tried migrating my code to match the JobIntentService but nothing is happening on bootup.
I am unsure whether the reason is because of my service class or my BroadcastReceiver class.



AndroidManifest.xml



    <service android:name=".backgroundService"
android:permission="android.permission.BIND_JOB_SERVICE"/>


backgroundService.java



    public class backgroundService extends JobIntentService {

public static final int JOB_ID = 0x01;

public static void enqueueWork(Context context, Intent work) {
enqueueWork(context, backgroundService.class, JOB_ID, work);
}


@Override
protected void onHandleWork(@NonNull Intent intent) {

Toast.makeText(this, "Application and Service Started", Toast.LENGTH_LONG).show();
Intent dialogIntent = new Intent(this, Home.class);
dialogIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
startActivity(dialogIntent);
}
}


startOnBoot.java



    public class startOnBoot extends BroadcastReceiver {
@Override
public void onReceive(Context context, Intent intent) {
if (intent.getAction() != null && intent.getAction().equals(Intent.ACTION_BOOT_COMPLETED)) {
Log.i("In" , "getAction() - Boot");
backgroundService.enqueueWork(context, intent);
}
else
Log.i("No" , "Boot");
}
}


So I am trying to essentially start the Home.class on bootup.







java android broadcastreceiver jobintentservice






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Jan 2 at 15:06









Rockey

297515




297515










asked Jan 2 at 14:42









godlypythongodlypython

778




778













  • Take a loot at stackoverflow.com/questions/6391902/…

    – Rockey
    Jan 2 at 14:44











  • This doesn't help because with android 8.0 you cannot use implicit broadcast receivers so I am trying to use a job intent service. The link doesn't provide any sort of help?

    – godlypython
    Jan 2 at 14:47











  • I think ACTION_BOOT_COMPLETED is still accepted on Android 8 stackoverflow.com/questions/45981888/…

    – Rockey
    Jan 2 at 14:52













  • Well..I have included this in my manifest as well. Still no luck. Not sure what the issue is.

    – godlypython
    Jan 2 at 15:07



















  • Take a loot at stackoverflow.com/questions/6391902/…

    – Rockey
    Jan 2 at 14:44











  • This doesn't help because with android 8.0 you cannot use implicit broadcast receivers so I am trying to use a job intent service. The link doesn't provide any sort of help?

    – godlypython
    Jan 2 at 14:47











  • I think ACTION_BOOT_COMPLETED is still accepted on Android 8 stackoverflow.com/questions/45981888/…

    – Rockey
    Jan 2 at 14:52













  • Well..I have included this in my manifest as well. Still no luck. Not sure what the issue is.

    – godlypython
    Jan 2 at 15:07

















Take a loot at stackoverflow.com/questions/6391902/…

– Rockey
Jan 2 at 14:44





Take a loot at stackoverflow.com/questions/6391902/…

– Rockey
Jan 2 at 14:44













This doesn't help because with android 8.0 you cannot use implicit broadcast receivers so I am trying to use a job intent service. The link doesn't provide any sort of help?

– godlypython
Jan 2 at 14:47





This doesn't help because with android 8.0 you cannot use implicit broadcast receivers so I am trying to use a job intent service. The link doesn't provide any sort of help?

– godlypython
Jan 2 at 14:47













I think ACTION_BOOT_COMPLETED is still accepted on Android 8 stackoverflow.com/questions/45981888/…

– Rockey
Jan 2 at 14:52







I think ACTION_BOOT_COMPLETED is still accepted on Android 8 stackoverflow.com/questions/45981888/…

– Rockey
Jan 2 at 14:52















Well..I have included this in my manifest as well. Still no luck. Not sure what the issue is.

– godlypython
Jan 2 at 15:07





Well..I have included this in my manifest as well. Still no luck. Not sure what the issue is.

– godlypython
Jan 2 at 15:07












1 Answer
1






active

oldest

votes


















0














I tried it and it could run normally. You could check three tips below.



1.Check whether you have declared RECEIVE_BOOT_COMPLETED permission or not.



<uses-permission android:name="android.permission.RECEIVE_BOOT_COMPLETED" />


2.Check whether you have declared the receiver with BOOT_COMPLETED action.



<receiver android:name=".startOnBoot">
<intent-filter>
<action android:name="android.intent.action.BOOT_COMPLETED" />
</intent-filter>
</receiver>


3.Remove Toast.makeText(this, "Application and Service Started", Toast.LENGTH_LONG).show(); in your service or toast it in main thread. Otherwise it gives you the error java.lang.RuntimeException: Can't toast on a thread that has not called Looper.prepare().






share|improve this answer























    Your Answer






    StackExchange.ifUsing("editor", function () {
    StackExchange.using("externalEditor", function () {
    StackExchange.using("snippets", function () {
    StackExchange.snippets.init();
    });
    });
    }, "code-snippets");

    StackExchange.ready(function() {
    var channelOptions = {
    tags: "".split(" "),
    id: "1"
    };
    initTagRenderer("".split(" "), "".split(" "), channelOptions);

    StackExchange.using("externalEditor", function() {
    // Have to fire editor after snippets, if snippets enabled
    if (StackExchange.settings.snippets.snippetsEnabled) {
    StackExchange.using("snippets", function() {
    createEditor();
    });
    }
    else {
    createEditor();
    }
    });

    function createEditor() {
    StackExchange.prepareEditor({
    heartbeatType: 'answer',
    autoActivateHeartbeat: false,
    convertImagesToLinks: true,
    noModals: true,
    showLowRepImageUploadWarning: true,
    reputationToPostImages: 10,
    bindNavPrevention: true,
    postfix: "",
    imageUploader: {
    brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
    contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
    allowUrls: true
    },
    onDemand: true,
    discardSelector: ".discard-answer"
    ,immediatelyShowMarkdownHelp:true
    });


    }
    });














    draft saved

    draft discarded


















    StackExchange.ready(
    function () {
    StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f54008295%2fandroid-8-0-job-intent-service-does-not-run-application-on-bootup%23new-answer', 'question_page');
    }
    );

    Post as a guest















    Required, but never shown

























    1 Answer
    1






    active

    oldest

    votes








    1 Answer
    1






    active

    oldest

    votes









    active

    oldest

    votes






    active

    oldest

    votes









    0














    I tried it and it could run normally. You could check three tips below.



    1.Check whether you have declared RECEIVE_BOOT_COMPLETED permission or not.



    <uses-permission android:name="android.permission.RECEIVE_BOOT_COMPLETED" />


    2.Check whether you have declared the receiver with BOOT_COMPLETED action.



    <receiver android:name=".startOnBoot">
    <intent-filter>
    <action android:name="android.intent.action.BOOT_COMPLETED" />
    </intent-filter>
    </receiver>


    3.Remove Toast.makeText(this, "Application and Service Started", Toast.LENGTH_LONG).show(); in your service or toast it in main thread. Otherwise it gives you the error java.lang.RuntimeException: Can't toast on a thread that has not called Looper.prepare().






    share|improve this answer




























      0














      I tried it and it could run normally. You could check three tips below.



      1.Check whether you have declared RECEIVE_BOOT_COMPLETED permission or not.



      <uses-permission android:name="android.permission.RECEIVE_BOOT_COMPLETED" />


      2.Check whether you have declared the receiver with BOOT_COMPLETED action.



      <receiver android:name=".startOnBoot">
      <intent-filter>
      <action android:name="android.intent.action.BOOT_COMPLETED" />
      </intent-filter>
      </receiver>


      3.Remove Toast.makeText(this, "Application and Service Started", Toast.LENGTH_LONG).show(); in your service or toast it in main thread. Otherwise it gives you the error java.lang.RuntimeException: Can't toast on a thread that has not called Looper.prepare().






      share|improve this answer


























        0












        0








        0







        I tried it and it could run normally. You could check three tips below.



        1.Check whether you have declared RECEIVE_BOOT_COMPLETED permission or not.



        <uses-permission android:name="android.permission.RECEIVE_BOOT_COMPLETED" />


        2.Check whether you have declared the receiver with BOOT_COMPLETED action.



        <receiver android:name=".startOnBoot">
        <intent-filter>
        <action android:name="android.intent.action.BOOT_COMPLETED" />
        </intent-filter>
        </receiver>


        3.Remove Toast.makeText(this, "Application and Service Started", Toast.LENGTH_LONG).show(); in your service or toast it in main thread. Otherwise it gives you the error java.lang.RuntimeException: Can't toast on a thread that has not called Looper.prepare().






        share|improve this answer













        I tried it and it could run normally. You could check three tips below.



        1.Check whether you have declared RECEIVE_BOOT_COMPLETED permission or not.



        <uses-permission android:name="android.permission.RECEIVE_BOOT_COMPLETED" />


        2.Check whether you have declared the receiver with BOOT_COMPLETED action.



        <receiver android:name=".startOnBoot">
        <intent-filter>
        <action android:name="android.intent.action.BOOT_COMPLETED" />
        </intent-filter>
        </receiver>


        3.Remove Toast.makeText(this, "Application and Service Started", Toast.LENGTH_LONG).show(); in your service or toast it in main thread. Otherwise it gives you the error java.lang.RuntimeException: Can't toast on a thread that has not called Looper.prepare().







        share|improve this answer












        share|improve this answer



        share|improve this answer










        answered Jan 2 at 15:51









        wolfhanwolfhan

        12




        12
































            draft saved

            draft discarded




















































            Thanks for contributing an answer to Stack Overflow!


            • Please be sure to answer the question. Provide details and share your research!

            But avoid



            • Asking for help, clarification, or responding to other answers.

            • Making statements based on opinion; back them up with references or personal experience.


            To learn more, see our tips on writing great answers.




            draft saved


            draft discarded














            StackExchange.ready(
            function () {
            StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f54008295%2fandroid-8-0-job-intent-service-does-not-run-application-on-bootup%23new-answer', 'question_page');
            }
            );

            Post as a guest















            Required, but never shown





















































            Required, but never shown














            Required, but never shown












            Required, but never shown







            Required, but never shown

































            Required, but never shown














            Required, but never shown












            Required, but never shown







            Required, but never shown







            Popular posts from this blog

            MongoDB - Not Authorized To Execute Command

            in spring boot 2.1 many test slices are not allowed anymore due to multiple @BootstrapWith

            Npm cannot find a required file even through it is in the searched directory