Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9199585
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T22:33:59+00:00 2026-06-17T22:33:59+00:00

I need my android app to be in background mode after a phone restart/power

  • 0

I need my android app to be in background mode after a phone restart/power on.

Currently I am using the following code, so that my app successfully gets launched after a phone restart/power on.

AndroidManifest.xml:

<receiver android:enabled="true" android:name="my_package.BootUpReceiver" android:permission="android.permission.RECEIVE_BOOT_COMPLETED" >
    <intent-filter>
        <action android:name="android.intent.action.BOOT_COMPLETED" />
        <category android:name="android.intent.category.DEFAULT" />
    </intent-filter>
</receiver>

BootUpReceiver.java:

public class BootUpReceiver extends BroadcastReceiver
{
    private static SharedPreferences aSharedSettings;

    @Override
    public void onReceive(Context context, Intent intent) 
    {
        aSharedSettings = context.getSharedPreferences("MyPreferences", Context.MODE_PRIVATE);
        boolean isUserLoggedIn = aSharedSettings.getBoolean(Key.AUTHENTICATED, false); 
        if(isUserLoggedIn) 
        {
            Intent aServiceIntent = new Intent(context, MyHomeView.class);
                    aServiceIntent.addCategory(Intent.CATEGORY_HOME);
            aServiceIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
                    context.startActivity(aServiceIntent); 
        }
    }
}

As I said above, my app successfully gets launched after a phone restart/power on.

However, after the phone restart/power on, my app was in foreground mode. But I need my app to be in background mode.

Can anyone please say, how to make an app to be in background mode after a phone restart or power on.

I even tried by changing the intent category to

<category android:name="android.intent.category.HOME" />

But no use in it. Can anyone please help me?

Thanks.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-17T22:34:01+00:00Added an answer on June 17, 2026 at 10:34 pm

    The suggestion which Leonidos replied is correct.

    However, Just a workaround for this:

    In my BootUpReceiver, I had a seperate boolean flag for this! (Its a bad way. but just a workaround)

    SharedPreferences.Editor aPrefEditor = aSharedSettings.edit();
    aPrefEditor.putBoolean(Key.IS_DEVICE_RESTARTED, true);
    aPrefEditor.commit();
    

    In Oncreate method of MyHomeView:

    boolean isDeviceRestarted = aSharedSettings.getBoolean(Key.IS_DEVICE_RESTARTED, false);
    if(isDeviceRestarted)
    {
        SharedPreferences.Editor aPrefEditor = aSharedSettings.edit();
        aPrefEditor.putBoolean(MamaBearKey.IS_DEVICE_RESTARTED, false);
        aPrefEditor.commit();
        moveTaskToBack(true);
    }
    

    Thanks

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I need to develop an android app that achieves the following: Create an activity
I'm in lean startup mode, working on a simple phone app that will be
Possible Duplicate: Run code when Android app is closed/sent to background In my android
My code is similar to the following: package com.javasamples; import android.app.Activity; import android.os.Bundle; import
I'm working on an Android app that uses uses a background worker thread. I
I'm developing an Android app that needs to do some updating in the background
I have written an android service, that I need to run in the background
In android app, I need to dynamically generate html and load that into webview
I need to resize/crop images in different resolutions for Android App. I know, that
I have an android app that uses a background service for uploading data. When

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.