Question

Je suis en train de lire les données à mon widget de après le démarrage de l'appareil.

Le récepteur de démarrage est la suivante:

    public class onBootReceiver extends BroadcastReceiver{

public static final String TAG = "BootReceiver";
private Context c;
@Override
public void onReceive(Context c, Intent i) {
    // TODO Auto-generated method stub

    boolean dontStop = true;
    while(dontStop)
    {
        try
        {   
            this.c=c;
            if(isExternalStorageMounted())
            {
                dontStop = false;
            }
            else
                for(int j=0;j<10000;j++)
                    Log.d(TAG, "###################### EXTERNAL STORAGE NOT MOUNTED ##########################");
        }
        catch (Exception e)
        {
            for(int j=0;j<10000;j++)
                Log.d(TAG, "###################### EXTERNAL STORAGE NOT MOUNTED ##########################");
        }
    }
    Intent externalStorageReady = new Intent(c, TheWidget.class);
    externalStorageReady.setAction(GlobalVars.WIDGET_INTENT_ACTION_READ_PREFS_AFTER_BOOT);
    c.sendBroadcast(externalStorageReady);

}
private boolean isExternalStorageMounted()
{
    String state = Environment.getExternalStorageState(); 
    if (Environment.MEDIA_REMOVED.equals(state))
    {
        return false; 
    }
    else if (Environment.MEDIA_SHARED.equals(state))
    {
        return false; 
    }
    else if (Environment.MEDIA_UNMOUNTABLE.equals(state))
    {
        return false; 
    }
    else if (Environment.MEDIA_UNMOUNTED.equals(state))
    {
        return false; 
    }
    return true;
}

}

Je sais que je reçois l'intention BOOT_COMPLETED (après l'avoir utilisé dans le widget lui-même), mais je ne peux pas lire mes données sauvegardées.

Je l'ai lu en utilisant SharedPreferences est la solution, mais ce que je sais est lorsque vous démarrez votre appareil, le SharedPreferences n'est plus là.

Je sauvegarde les données en interne à l'aide intégrée dans SQL dans le SDK Android.

S'il vous plaît aider ...: (

Était-ce utile?

La solution

External storage may not be ready by the time of a BOOT_COMPLETED broadcast. And your loops are pointless.

but what i know is when you boot your device, the SharedPreferences is no longer there.

Yes, SharedPreferences are there at boot time.

i save the data internally using built-in SQL in the android sdk.

Then it is unclear why you are waiting on external storage, since your data is not on external storage.

Any form of I/O may take too long, though, right at boot time. Have your BroadcastReceiver call startService() on an IntentService that can read your database or SharedPreferences in onHandleIntent() and update your app widget.

Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow
scroll top