Example usage for android.content Context MODE_MULTI_PROCESS

List of usage examples for android.content Context MODE_MULTI_PROCESS

Introduction

In this page you can find the example usage for android.content Context MODE_MULTI_PROCESS.

Prototype

int MODE_MULTI_PROCESS

To view the source code for android.content Context MODE_MULTI_PROCESS.

Click Source Link

Document

SharedPreference loading flag: when set, the file on disk will be checked for modification even if the shared preferences instance is already loaded in this process.

Usage

From source file:org.zywx.wbpalmstar.platform.push.PushService.java

private void start() {
    String appKey = EUExUtil.getString("appkey");
    appKey = PushReportUtility.decodeStr(appKey);
    softToken = PushReportUtility.getSoftToken(this, appKey);
    preferences = this.getSharedPreferences(PushReportConstants.SP_APP, Context.MODE_PRIVATE);
    url_push = ResoureFinder.getInstance().getString(this, "push_host");
    if (TextUtils.isEmpty(url_push)) {
        Log.w("PushService", "push_host is empty");
        return;//  w w  w  .j  ava 2s.co  m
    }
    // String host_and_port = ResoureFinder.getInstance().getString(this,
    // "mam_push_host_and_port");
    // if (!TextUtils.isEmpty(host_and_port)) {
    // mamPush_ip = host_and_port.split(":")[0];
    // mamPush_port = host_and_port.split(":")[1];
    // }
    SharedPreferences sp = this.getSharedPreferences("saveData", Context.MODE_MULTI_PROCESS);
    String pushMes = sp.getString("pushMes", "0");
    String localPushMes = sp.getString("localPushMes", pushMes);
    if ("1".equals(localPushMes) && "1".equals(pushMes)) {
        type = 1;
    } else {
        type = 0;
    }
    try {
        // type = intent.getIntExtra("type", 0);
        // System.out.println("res ==== "+type);
        if (type == 0) {
            if (pushGetData != null) {
                ((MQTTService) pushGetData).onDestroy();
            }
            // runStatus = Status.PENDING;
            return;
        }
        // System.out.println("runStatus ==== RUNNING");
        // runStatus = Status.RUNNING;
        if (pushGetData == null) {
            String softToken = preferences.getString("softToken", null);
            pushGetData = new MQTTService(this, url_push, this, softToken);
            ((MQTTService) pushGetData).init();
        } else {
            /**?????? 
             * wanglei 20160314 modify*/
            Context ctx = getApplicationContext();
            Intent mQttPingIntent = new Intent(MQTTService.MQTT_PING_ACTION);
            mQttPingIntent.setPackage(ctx.getPackageName());
            ctx.sendBroadcast(mQttPingIntent);
            //                ((MQTTService) pushGetData).onDestroy();
            //                ((MQTTService) pushGetData).init();
        }

    } catch (Exception e) {
        // TODO: handle exception
    }

    // sleepTime = 1000;
    // if (isTemporary) {
    // sleepTime = 1000 * 30;
    // } else {
    // sleepTime = 1000 * 60 * 2;
    // }
    //
    // if (timer == null) {
    // timer = new Timer();
    // }
    //
    // if (myTimerTask == null) {
    // myTimerTask = new MyTimerTask();
    // }
    //
    // timer.schedule(myTimerTask, 0, sleepTime);

    // sendData = "{\"cmd\":\"reg\",\"appid\":\""
    // + preferences.getString("appid", null) + "\",\"st\":\""
    // + preferences.getString("softToken", null) + "\"}";
    // onReceive();
    // receiveData();
    // super.onStart(intent, startId);
}

From source file:main.MainActivity.java

@Override
public void onResume() {
    super.onResume();

    Database db = Database.getInstance(this);
    // read todays offset
    todayOffset = db.getSteps(Util.getToday());

    SharedPreferences prefs = MainActivity.this.getSharedPreferences("pedometer", Context.MODE_MULTI_PROCESS);

    since_boot = db.getCurrentSteps(); // do not use the value from the sharedPreferences
    int pauseDifference = since_boot - prefs.getInt("pauseCount", since_boot);

    // register a sensorlistener to live update the UI if a step is taken
    // Start detecting
    //        mStepDetector = new StepDetector();
    //        mSensorManager = (SensorManager) getSystemService(SENSOR_SERVICE);
    //        registerDetector();
    //        mStepDetector.setSensitivity(10);

    since_boot -= pauseDifference;/*w  ww  . ja va  2  s .c  om*/
    total_start = db.getTotalWithoutToday();

    db.close();

}

From source file:me.piebridge.bible.Bible.java

private Bible(Context context) {
    Log.d(TAG, "init bible");
    mContext = context;//  www .  ja  v a 2  s  .c  om
    SharedPreferences preferences = mContext.getSharedPreferences(HUMAN_PREFERENCE, Context.MODE_MULTI_PROCESS);
    for (Entry<String, ?> entry : preferences.getAll().entrySet()) {
        allhuman.put(entry.getKey(), String.valueOf(entry.getValue()));
    }
    try {
        versionName = context.getPackageManager().getPackageInfo(context.getPackageName(), 0).versionName;
    } catch (NameNotFoundException e) {
    }
    checkLocale();
    setDefaultVersion();
}

From source file:com.darshancomputing.BatteryIndicatorPro.PersistentFragment.java

public void loadSettingsFiles() {
    settings = getActivity().getSharedPreferences(SettingsActivity.SETTINGS_FILE, Context.MODE_MULTI_PROCESS);
    sp_service = getActivity().getSharedPreferences(SettingsActivity.SP_SERVICE_FILE,
            Context.MODE_MULTI_PROCESS);
    sp_main = getActivity().getSharedPreferences(SettingsActivity.SP_MAIN_FILE, Context.MODE_MULTI_PROCESS);
}

From source file:Steps.StepsFragment.java

@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
    View rootView = inflater.inflate(R.layout.steps_fragment, container, false);
    ViewCompat.setElevation(rootView, 50);
    Log.w("Create VIew", "HERE");

    textToGo = (TextView) rootView.findViewById(R.id.textRemaining);
    textSteps = (TextView) rootView.findViewById(R.id.textSteps);
    textGoal = (TextView) rootView.findViewById(R.id.textCurrentGoal);
    textNextPack = (TextView) rootView.findViewById(R.id.textView3);
    isChecked = true;/*  ww w.  j  ava 2  s  .  c o m*/
    goalAnimationPlaying = false;

    SharedPreferences prefs = getActivity().getSharedPreferences("pedometer", Context.MODE_MULTI_PROCESS);
    int availableStickerPacks = prefs.getInt("packs", 0);

    buttonOpenPack = (TextView) rootView.findViewById(R.id.packButton);
    buttonOpenPack.setText(Integer.toString(availableStickerPacks) + " New Packs");
    //if the open pack button is pressed
    buttonOpenPack.setOnClickListener(new Button.OnClickListener() {
        public void onClick(View v) {
            SharedPreferences prefs = getActivity().getSharedPreferences("pedometer",
                    Context.MODE_MULTI_PROCESS);
            int availableStickerPacks = prefs.getInt("packs", 0);
            buttonOpenPack.setText(Integer.toString(availableStickerPacks) + " New Packs");
            //if you have stikers for opening
            if (availableStickerPacks > 0) {
                //pick 3 stickers randomly
                int sticker1 = rg.getDistributedRandomNumber();
                int sticker2 = rg.getDistributedRandomNumber();
                int sticker3 = rg.getDistributedRandomNumber();
                Database db = Database.getInstance(getActivity());
                final Sticker sticker_1 = db.getSticker(sticker1);
                final Sticker sticker_2 = db.getSticker(sticker2);
                final Sticker sticker_3 = db.getSticker(sticker3);
                db.close();
                //open the new dialog displaying them
                showNewSticker(sticker_1, sticker_2, sticker_3);
                Log.w("pressButton", "pressed");
                //update the availalbe sticker count
                updateStickerPackCountDecrease();
                //check for the achievement
                updateCountForAchievements();
                //update the statuses and counts in the database for the three stickers
                updateCountAndStatusDatabase(sticker_1, sticker_2, sticker_3);
                //notify all other views for a sticker change
                notifyActivityStickerStatusChange.notifyChange();
            } else {
                Toast.makeText(getActivity(), "You don't have any stickers to open right now",
                        Toast.LENGTH_LONG).show();
            }

        }
    });

    //code for initializing the arc progress step bar
    mDecoView = (DecoView) rootView.findViewById(R.id.dynamicArcView);
    createBackSeries();
    createDataSeries1();
    mDecoView.executeReset();

    //animation
    mDecoView
            .addEvent(new DecoEvent.Builder(goal).setIndex(mBackIndex).setDuration(3000).setDelay(100).build());
    //second animation
    mDecoView.addEvent(new DecoEvent.Builder(DecoDrawEffect.EffectType.EFFECT_SPIRAL_OUT_FILL)
            .setIndex(mSeries1Index).setDuration(3000).setDelay(1250).build());

    //togle between distance and steps
    mDecoView.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            if (!isChecked) {
                // show steps
                isChecked = true;
                updateViews();

            } else {
                //showDistance
                isChecked = false;
                updateViews();
            }
        }

    });

    ImageView img = (ImageView) rootView.findViewById(R.id.trendsImage);
    //if the trends image is clicked start a new activity displaying the charts
    img.setOnClickListener(new View.OnClickListener() {
        public void onClick(View v) {
            Log.w("Test", "Trends Clicked");
            Intent intent = new Intent(getActivity(), CombinedChartActivity.class);
            startActivity(intent);
        }
    });

    return rootView;
}

From source file:net.bither.preference.PersistentCookieStore.java

@SuppressLint("InlinedApi")
public void reload() {
    // Load any previously stored cookies into the store
    this.cookiePrefs = BitherApplication.mContext.getSharedPreferences(COOKIE_PREFS,
            Context.MODE_MULTI_PROCESS);
    cookies = new ConcurrentHashMap<String, Cookie>();

    String storedCookieNames = this.cookiePrefs.getString(COOKIE_NAME_STORE, null);
    if (storedCookieNames != null) {
        String[] cookieNames = TextUtils.split(storedCookieNames, ",");
        for (String name : cookieNames) {
            String encodedCookie = this.cookiePrefs.getString(COOKIE_NAME_PREFIX + name, null);
            if (encodedCookie != null) {
                Cookie decodedCookie = decodeCookie(encodedCookie);
                if (decodedCookie != null) {
                    cookies.put(name, decodedCookie);
                }/* w  w  w .ja v  a  2  s. c om*/
            }
        }

        // Clear out expired cookies
        clearExpired(new Date());
    }
}

From source file:com.github.caifatcmd.VolumeService.java

@Override
protected void onHandleIntent(Intent intent) {
    pref = getApplicationContext().getSharedPreferences(PREF_NAME, Context.MODE_MULTI_PROCESS);
    // Extract volume request from intent
    gotoVolume = intent.getIntExtra(CURR_VOL_KEY, currentVolume);
    if (gotoVolume < DEFAULT_MIN_VOL)
        gotoVolume = DEFAULT_MIN_VOL;/*from   w ww. j a v  a2  s. c o m*/
    Log.d("CallVolService", "Changing volume to " + currentVolume);
    Integer retVal = runATCmd(gotoVolume);
    if (retVal >= 0) {
        currentVolume = gotoVolume;
        pref.edit().putInt(CURR_VOL_KEY, currentVolume).commit();
        //pref.edit().commit();
        Log.d("CallVolService", "Volume applied!");

        Intent localIntent = new Intent(UPDATED);
        broadcaster.sendBroadcast(localIntent);
    }
}

From source file:de.j4velin.wifiAutoOff.Locations.java

@Override
protected void onCreate(final Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

    Database db = Database.getInstance(this);
    locations = db.getLocations();/*from  www .  j a va  2s.c o m*/
    db.close();

    setContentView(R.layout.locations);

    findViewById(R.id.fab).setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(final View v) {
            if (PREMIUM_ENABLED || locations.size() < 1) {
                startActivityForResult(new Intent(Locations.this, Map.class), REQUEST_LOCATION);
            } else {
                AlertDialog.Builder builder = new AlertDialog.Builder(Locations.this);
                builder.setMessage(R.string.buy_pro);
                builder.setPositiveButton(android.R.string.yes, new DialogInterface.OnClickListener() {
                    @Override
                    public void onClick(final DialogInterface dialog, int which) {
                        try {
                            Bundle buyIntentBundle = mService.getBuyIntent(3, getPackageName(),
                                    "de.j4velin.wifiautomatic.billing.pro", "inapp", getPackageName());
                            if (buyIntentBundle.getInt("RESPONSE_CODE") == 0) {
                                PendingIntent pendingIntent = buyIntentBundle.getParcelable("BUY_INTENT");
                                startIntentSenderForResult(pendingIntent.getIntentSender(), REQUEST_BUY, null,
                                        0, 0, 0);
                            }
                        } catch (Exception e) {
                            if (BuildConfig.DEBUG)
                                Logger.log(e);
                            Toast.makeText(Locations.this, e.getClass().getName() + ": " + e.getMessage(),
                                    Toast.LENGTH_LONG).show();
                            e.printStackTrace();
                        }
                        dialog.dismiss();
                    }
                });
                builder.setNegativeButton(android.R.string.no, new DialogInterface.OnClickListener() {
                    @Override
                    public void onClick(final DialogInterface dialog, int which) {
                        dialog.dismiss();
                    }
                });
                builder.create().show();
            }
        }
    });

    mRecyclerView = (RecyclerView) findViewById(R.id.locations);
    mRecyclerView.setHasFixedSize(true);
    mRecyclerView.setLayoutManager(new LinearLayoutManager(this, LinearLayoutManager.VERTICAL, false));
    mAdapter = new LocationsAdapter();
    mRecyclerView.setAdapter(mAdapter);

    PREMIUM_ENABLED |= getSharedPreferences("settings", Context.MODE_PRIVATE).getBoolean("pro", false);
    if (!PREMIUM_ENABLED) {
        bindService(new Intent("com.android.vending.billing.InAppBillingService.BIND")
                .setPackage("com.android.vending"), mServiceConn, Context.BIND_AUTO_CREATE);
    }

    findViewById(R.id.timeoutwarning).setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(final View v) {
            getSharedPreferences(getPackageName() + "_preferences", Context.MODE_MULTI_PROCESS).edit()
                    .putInt("no_network_timeout", 5).commit();
            v.setVisibility(View.GONE);
        }
    });

}

From source file:com.nextgis.firereporter.ScanexSubscriptionItem.java

public void UpdateFromRemote(String sCookie) {
    if (c == null)
        return;//from   w  w  w . ja  va2 s.c o m
    //get notifications http://fires.kosmosnimki.ru/SAPI/Subscribe/GetData/55?dt=2013-08-06&CallBackName=44
    Calendar calendar = Calendar.getInstance();

    SharedPreferences prefs = c.getSharedPreferences(MainActivity.PREFERENCES,
            Context.MODE_PRIVATE | Context.MODE_MULTI_PROCESS);
    int nPrevDays = prefs.getInt(SettingsActivity.KEY_PREF_SEARCH_DAY_INTERVAL + "_int", PREV_DAYS);

    for (int i = 0; i < nPrevDays; i++) {
        String sDate = String.format("%04d-%02d-%02d", calendar.get(Calendar.YEAR),
                calendar.get(Calendar.MONTH) + 1, calendar.get(Calendar.DAY_OF_MONTH));
        Log.d(MainActivity.TAG, sDate);
        String sURL = GetFiresService.SCANEX_API + "/Subscribe/GetData/" + nID + "?dt=" + sDate
                + "&CallBackName=" + GetFiresService.USER_ID;
        Log.d(MainActivity.TAG, sURL);
        new HttpGetter(c, 5, "", mFillDataHandler, false).execute(sURL, sCookie);

        calendar.roll(Calendar.DAY_OF_MONTH, false);
    }
}

From source file:org.anhonesteffort.flock.sync.AbstractDavSyncAdapter.java

private boolean isAuthNotificationDisabled() {
    SharedPreferences settings = getContext().getSharedPreferences(PREFERENCES_NAME,
            Context.MODE_MULTI_PROCESS);

    if (settings.getBoolean(KEY_VOID_AUTH_NOTIFICATIONS + getAuthority(), false)) {
        settings.edit().putBoolean(KEY_VOID_AUTH_NOTIFICATIONS + getAuthority(), false).commit();
        Log.e(TAG, "auth notification is disabled for " + getAuthority());
        return true;
    }/* ww  w.  jav  a 2s . c o m*/

    Log.e(TAG, "auth notification is not disabled for " + getAuthority());
    return false;
}