在广播接收器之前运行的启动器活动

时间:2016-06-29 01:08:15

标签: android android-intent android-activity broadcastreceiver

休斯顿我有一个问题,就在这里:

我有一个广播接收器,在我的应用更新后运行,我已经实现了这个:

Android 清单,位于<application>标记内:

    <receiver
        android:name=".control.background.services.UpdateReceiver"
        android:enabled="true"
        android:exported="false">
        <intent-filter>
            <action android:name="android.intent.action.PACKAGE_REPLACED"/>
            <data android:scheme="package" android:path="br.com.soutsapp.waiter.soutsw" />
        </intent-filter>

    </receiver>

BroadcastReceiver 类:

public class UpdateReceiver extends BroadcastReceiver {
    public UpdateReceiver() {
    }

    @Override
    public void onReceive(Context context, Intent intent) {
        if(intent.getAction().equals(Intent.ACTION_PACKAGE_REPLACED)){
            String packageName = context.getPackageName();
            if(packageName.equalsIgnoreCase("br.com.soutsapp.Souts_v3")){
                final Context appContext = context.getApplicationContext();

                SharedPreferences sp = appContext.getSharedPreferences(ConstantUtils.SHARED_PREFERENCES, Context.MODE_PRIVATE);
                String json = sp.getString(ConstantUtils.TAG_SHARED_PREFERENCES_USER_INFO, null);

                UserModel user = null;
                if(json != null){
                    user = new JsonParserUtils<>(UserModel.class).serialize(json);
                }

                if(user != null && user.getFacebookUserId() != null && user.getFacebookUserId().length() > 0){
                    FacebookSdk.sdkInitialize(appContext);
                    LoginManager.getInstance().logOut();
                }

                sp.edit().clear().commit();

                Log.d("SOUTS", "Running broadcast receiver");

            }
        }
    }
}

在我的启动器活动中,我在onCreate结束时打印了一个日志;

当我的应用程序以更新运行时,我得到了这两个打印件:

  

06-28 21:58:48.629 24984-24984 / br.com.soutsapp.Souts_v3 D / SOUTS:   在onCreate EstablishmentActivity上运行

     

06-28 21:58:51.572 24984-24984 / br.com.soutsapp.Souts_v3 D / SOUTS:   运行广播接收器

正如您所看到的,广播接收器在Launcher活动后3秒运行,所以这里提出我的问题,是否有办法确保我的BroadcastReceiver将在我的Launcher活动之前运行?

如果没有,你会建议我解决这个问题吗?

0 个答案:

没有答案