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 6342937
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T20:20:26+00:00 2026-05-24T20:20:26+00:00

I am having a strange problem in an Android application that I am building,

  • 0

I am having a strange problem in an Android application that I am building, the application is basically a Homescreen replacement app which will be put as a default homescreen in a device. To do some initialization work I have extended Android Application class and in the onCreate() method I am basically registering some observer and starting a service, here’s the code:

public class MyApplication extends Application implements ExternalStorageListener {
    private ExternalStorageObserver externalStorageObserver;

    public void onCreate() {
        Log.i("MyApplication", "Starting application");
        super.onCreate();

        externalStorageObserver = new ExternalStorageObserver(this);

        if(externalStorageObserver.isExternalStorageAvailable()) {
            // this builds a list of files present in the SD card
            // which is being used through the application to do
            // some work
            buildData();

            File externalFileDir = getApplicationContext().getExternalFilesDir(null);
            if(externalFileDir != null && externalFileDir.isDirectory()) {
                // do something...  
            } 
        }

        //Register listener to observe external storage state
        registerExternalStorageObserver(); 

        Log.i("SyncService", "Starting sync service...");
        ComponentName cmp = startService(new Intent(getApplicationContext(), SyncService.class));
        Log.i("SyncService", cmp.toString());
    }


    private void registerExternalStorageObserver() {
        IntentFilter filter = new IntentFilter();
        filter.addAction(Intent.ACTION_MEDIA_MOUNTED);
        filter.addAction(Intent.ACTION_MEDIA_REMOVED);
        registerReceiver(externalStorageObserver, filter);
    }

    private void buildData() {
        // builds a list
    }   
}

Content of Manifest file:

<application android:persistent="true" android:icon="@drawable/icon"
    android:label="@string/app_name" android:name="com.webgyani.android.MyApplication"
    android:debuggable="true">

    <activity android:name=".HomeTabActivity" android:launchMode="singleInstance"
        android:stateNotNeeded="true" android:theme="@style/LightTabsTheme"
        android:screenOrientation="landscape" android:label="@string/app_name">
        <intent-filter>
            <action android:name="android.intent.action.MAIN" />
            <category android:name="android.intent.category.HOME" />
            <category android:name="android.intent.category.DEFAULT" />
        </intent-filter>
    </activity>
</application>

This works fine when I install the app either using Eclipse or manually installing the apk onto the device. Once the app is installed things work fine, I mean the above onCreate() method gets called and service is also started normally, but if I reboot the device this time the onCreate() method does not get called(none of the log statements appear and also the services are not started). After some debugging I noticed that this only happens if I set my app as the default launcher/homescreen app and thereafter reboots the device, because once you set the app as the default launcher, Android should automatically launch your app as the homescreen after reboot. In my case the app is launched but that code is not executed.

I tried to use debugger but that didn’t work because when I reboot the device the debugger gets disconnected and by the time USB debugging gets enabled my app is already started.

I even double checked the Logcat but didn’t see any error. I thought of having a BOOT_COMPLETED intent to initialize that part, but that will require some code refactoring which I am not willing to do at this point of time unless there is a solution.

So I am curious to know that whether this is a standard behavior, or is there a known bug which causes this, because my assumption is the onCreate method of the Application will always get called whenever the app is started. I have tried whatever I could since morning, but nothing worked, couldn’t pinpoint the issue, if any of you could shed some light into this then that would be highly appreciated.

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-05-24T20:20:27+00:00Added an answer on May 24, 2026 at 8:20 pm

    Well, finally I figured out the problem, and it was in my code itself. I initially suspected that the MyApplication‘s onCreate() method was not getting called, I had that assumption because I was not able to see any logs. To know whether the method is getting called or not, instead of using Log.i() I was also appending some additional log messages in an ArrayList and printing them later, this revealed that the methods were indeed getting called and even the Service was instantiating properly but the data or filelist is not being populated because the SDCard was not ready by that time. I am also pretty sure that the logs were not available on Logcat due to the fact that the USB debugger becomes ready after my app is started(as it’s a homescreen app).

    The actual problem becomes obvious when you see that my overridden MyApplication class implements a listener called ExternalStorageListener which basically extends BroadcastReceiver, I have created that class to receive SDCard related Intents for example ACTION_MEDIA_MOUNTED, ACTION_MEDIA_REMOVED to rebuild the data(file list). In my case the ExternalStorageListener class was not receiving the Intents because I forgot to add this filter.addDataScheme("file") in the registerExternalStorageObserver method above in the code sample.

    I do agree that my question was based on a false assumption and the code example I posted it’s kind of hard to figure out the actual issue. I am not sure what to do with the question whether to mark this as answer or leave it as it is.

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

Sidebar

Related Questions

I'm having a strange problem here... I have an ASP.NET 3.5 application that has
I'm having a strange problem. I have to use GetPostBackEventRefence to force a Postback,
I'm having a strange problem in Visual Studio 2008 where my Pending Checkins window
I just installed the JIRA connector for VS2010 and having a strange problem adding
I'm having a really odd problem (which usually means I'm doing something wrong) with
Having a strange issue with some C# code - the Getter method for a
I am having a strange DB2 issue when I run DBUnit tests. My DBUnit
I am having a very strange behavior in JBoss, and I'd like avail myself
I'm having a really strange issue with a redirect in my .htaccess. The rule
At this moment we are building a new architecture that is based on the

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.