Example usage for android.content Context LOCATION_SERVICE

List of usage examples for android.content Context LOCATION_SERVICE

Introduction

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

Prototype

String LOCATION_SERVICE

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

Click Source Link

Document

Use with #getSystemService(String) to retrieve a android.location.LocationManager for controlling location updates.

Usage

From source file:com.example.administrator.myapplication2._2_exercise._2_Status_heart.fragments.LeftFragment.java

/**
 *   ??  ? //from   w ww  . j av  a 2  s  .  c o  m
 */
private void startLocationService() {
    //  ? ? 
    manager = (LocationManager) getActivity().getSystemService(Context.LOCATION_SERVICE);

    //   ?   ? ?
    gpsListener = new GPSListener();
    long minTime = 5000;//GPS    - 20  
    float minDistance = 1;//?? (10m)

    // GPS   
    manager.requestLocationUpdates(LocationManager.GPS_PROVIDER, minTime, minDistance, gpsListener);

    // ?   
    manager.requestLocationUpdates(LocationManager.NETWORK_PROVIDER, minTime, minDistance, gpsListener);

    /*   //  ?? ? ?? ? ??    ?
       try {
    Location lastLocation = manager.getLastKnownLocation(LocationManager.GPS_PROVIDER);
    if (lastLocation != null) {
        Double latitude = lastLocation.getLatitude();
        Double longitude = lastLocation.getLongitude();
            
    }
       } catch(Exception ex) {
    ex.printStackTrace();
       }*/

}

From source file:eu.basicairdata.graziano.gpslogger.GPSApplication.java

@Override
public void onCreate() {
    super.onCreate();
    singleton = this;

    StartAndBindGPSService();//  w  ww .  j a  v  a 2  s.c  o m

    EventBus.getDefault().register(this);

    mlocManager = (LocationManager) getSystemService(Context.LOCATION_SERVICE); // Location Manager

    File sd = new File(Environment.getExternalStorageDirectory() + "/GPSLogger"); // Create the Directories if not exist
    if (!sd.exists()) {
        sd.mkdir();
        Log.w("myApp", "[#] GPSApplication.java - Folder created: " + sd.getAbsolutePath());
    }
    sd = new File(Environment.getExternalStorageDirectory() + "/GPSLogger/AppData");
    if (!sd.exists()) {
        sd.mkdir();
        Log.w("myApp", "[#] GPSApplication.java - Folder created: " + sd.getAbsolutePath());
    }

    sd = new File(getApplicationContext().getFilesDir() + "/Thumbnails");
    if (!sd.exists()) {
        sd.mkdir();
        Log.w("myApp", "[#] GPSApplication.java - Folder created: " + sd.getAbsolutePath());
    }

    EGM96 egm96 = EGM96.getInstance(); // Load EGM Grid
    if (egm96 != null) {
        if (!egm96.isEGMGridLoaded()) {
            egm96.LoadGridFromFile(Environment.getExternalStorageDirectory() + "/GPSLogger/AppData/WW15MGH.DAC",
                    getApplicationContext().getFilesDir() + "/WW15MGH.DAC");
        }
    }

    GPSDataBase = new DatabaseHandler(this); // Initialize the Database

    // Prepare the current track
    if (GPSDataBase.getLastTrackID() == 0)
        GPSDataBase.addTrack(new Track()); // Creation of the first track if the DB is empty
    _currentTrack = GPSDataBase.getLastTrack(); // Get the last track

    LoadPreferences(); // Load Settings

    // ----------------------------------------------------------------------------------------

    asyncUpdateThread.start();
    AsyncTODO ast = new AsyncTODO();
    ast.TaskType = "TASK_NEWTRACK";
    ast.location = null;
    AsyncTODOQueue.add(ast);

    // Get max available VM memory, exceeding this amount will throw an
    // OutOfMemory exception. Stored in kilobytes as LruCache takes an
    // int in its constructor.
    Log.w("myApp", "[#] GPSApplication.java - Max available VM memory = "
            + (int) (Runtime.getRuntime().maxMemory() / 1024) + " kbytes");

}

From source file:com.example.mapdemo.BasicMapDemoActivity.java

private void setGeoLocation() {
    latitude = (TextView) findViewById(R.id.lat);
    longitude = (TextView) findViewById(R.id.lon);
    altitude = (TextView) findViewById(R.id.alt);
    heading = (TextView) findViewById(R.id.hea);

    provText = (TextView) findViewById(R.id.prov);
    choice = (TextView) findViewById(R.id.choice);
    fineAcc = (CheckBox) findViewById(R.id.fineAccuracy);
    choose = (Button) findViewById(R.id.chooseRadio);
    // Get the location manager
    locationManager = (LocationManager) getSystemService(Context.LOCATION_SERVICE);
    // Define the criteria how to select the location provider
    criteria = new Criteria();
    criteria.setAccuracy(Criteria.ACCURACY_COARSE); //default

    // user defines the criteria
    choose.setOnClickListener(new View.OnClickListener() {
        @Override/*from  www  .  j  a v  a  2 s  .  c o  m*/
        public void onClick(View v) {
            // TODO Auto-generated method stub
            if (fineAcc.isChecked()) {
                criteria.setAccuracy(Criteria.ACCURACY_FINE);
                choice.setText("fine accuracy selected");
            } else {
                criteria.setAccuracy(Criteria.ACCURACY_COARSE);
                choice.setText("coarse accuracy selected");
            }
        }
    });
    criteria.setCostAllowed(false);
    // get the best provider depending on the criteria
    provider = locationManager.getBestProvider(criteria, false);
    // the last known location of this provider
    Location location = locationManager.getLastKnownLocation(provider);
    mylistener = new MyLocationListener();
    if (location != null) {
        mylistener.onLocationChanged(location);
    } else {
        // leads to the settings because there is no last known location
        Intent intent = new Intent(Settings.ACTION_LOCATION_SOURCE_SETTINGS);
        startActivity(intent);
    }
    // location updates: at least 1 meter and 200 millsecs change
    locationManager.requestLocationUpdates(provider, 200, 1, mylistener);
}

From source file:com.alibaba.weex.extend.module.location.DefaultLocation.java

private WXLocationListener findLocation(String watchId, String sucCallback, String errorCallback,
        boolean enableHighAccuracy, boolean enableAddress) {
    //    WXLogUtils.d(TAG, "into--[findLocation] mWatchId:" + watchId + "\nsuccessCallback:" + sucCallback + "\nerrorCallback:" + errorCallback + "\nenableHighAccuracy:" + enableHighAccuracy + "\nmEnableAddress:" + enableAddress);

    if (mLocationManager == null) {
        mLocationManager = (LocationManager) mWXSDKInstance.getContext()
                .getSystemService(Context.LOCATION_SERVICE);
    }//from  w ww  .  j  a  v  a 2s. com
    Criteria criteria = new Criteria();
    if (enableHighAccuracy) {
        criteria.setAccuracy(Criteria.ACCURACY_COARSE);
    }
    //String provider = locationManager.getBestProvider(criteria, false);
    if (ActivityCompat.checkSelfPermission(mWXSDKInstance.getContext(),
            Manifest.permission.ACCESS_FINE_LOCATION) == PackageManager.PERMISSION_GRANTED
            && ActivityCompat.checkSelfPermission(mWXSDKInstance.getContext(),
                    Manifest.permission.ACCESS_COARSE_LOCATION) == PackageManager.PERMISSION_GRANTED) {
        WXLocationListener WXLocationListener = new WXLocationListener(mLocationManager, mWXSDKInstance,
                watchId, sucCallback, errorCallback, enableAddress);
        mLocationManager.requestLocationUpdates(LocationManager.GPS_PROVIDER, MIN_TIME, MIN_DISTANCE,
                WXLocationListener);
        mLocationManager.requestLocationUpdates(LocationManager.NETWORK_PROVIDER, MIN_TIME, MIN_DISTANCE,
                WXLocationListener);
        return WXLocationListener;
    } else {
        Map<String, Object> options = new HashMap<>();
        options.put(ERROR_CODE, ErrorCode.NO_PERMISSION_ERROR);
        options.put(ERROR_MSG, ErrorMsg.NO_PERMISSION_ERROR);
        WXSDKManager.getInstance().callback(mWXSDKInstance.getInstanceId(), errorCallback, options);
    }
    return null;
}

From source file:de.sindzinski.wetter.MainActivity.java

public Location getLocation() {
    Location location = null;//from ww w.j a v a 2 s  .  c om
    String provider = "";
    String locationSetting = "";

    if (!checkAndAskForPermission()) {
        return null;
    }

    try {
        // Get the location manager
        LocationManager locationManager = (LocationManager) getSystemService(Context.LOCATION_SERVICE);
        // Define the criteria how to select the locatioin provider -> use
        // default
        Criteria criteria = new Criteria();
        if (locationManager != null) {
            provider = locationManager.getBestProvider(criteria, false);
            location = locationManager.getLastKnownLocation(provider);
        }

    } catch (Exception ex) {
        Log.e(LOG_TAG, "Error creating location service: " + ex.getMessage());
    }

    return location;
}

From source file:com.keysolutions.meteorparties.PartyMapFragment.java

/**
 * Gets current location using Android's location provider
 * so you can zoom the map to it//w  ww  . j a  va 2 s .com
 * @return last known Location
 */
@SuppressWarnings("unused")
private Location getCurrentLocation() {
    Criteria criteria = new Criteria();
    LocationManager locMan = (LocationManager) getActivity().getSystemService(Context.LOCATION_SERVICE);
    String towers = locMan.getBestProvider(criteria, false);
    Location location = locMan.getLastKnownLocation(towers);
    return location;
}

From source file:com.shafiq.myfeedle.core.MyfeedleCreatePost.java

@Override
public boolean onOptionsItemSelected(MenuItem item) {
    int itemId = item.getItemId();
    if (itemId == R.id.menu_post_accounts)
        chooseAccounts();/*from   w ww .  ja v  a 2s  . c  om*/
    else if (itemId == R.id.menu_post_photo) {
        boolean supported = false;
        Iterator<Integer> services = mAccountsService.values().iterator();
        while (services.hasNext() && ((supported = sPhotoSupported.contains(services.next())) == false))
            ;
        if (supported) {
            Intent intent = new Intent();
            intent.setType("image/*");
            intent.setAction(Intent.ACTION_GET_CONTENT);
            startActivityForResult(Intent.createChooser(intent, "Select Picture"), PHOTO);
        } else
            unsupportedToast(sPhotoSupported);
        //      } else if (itemId == R.id.menu_post_tags) {
        //         if (mAccountsService.size() == 1) {
        //            if (sTaggingSupported.contains(mAccountsService.values().iterator().next()))
        //               selectFriends(mAccountsService.keySet().iterator().next());
        //            else
        //               unsupportedToast(sTaggingSupported);
        //         } else {
        //            // dialog to select an account
        //            Iterator<Long> accountIds = mAccountsService.keySet().iterator();
        //            HashMap<Long, String> accountEntries = new HashMap<Long, String>();
        //            while (accountIds.hasNext()) {
        //               Long accountId = accountIds.next();
        //               Cursor account = this.getContentResolver().query(Accounts.getContentUri(this), new String[]{Accounts._ID, ACCOUNTS_QUERY}, Accounts._ID + "=?", new String[]{Long.toString(accountId)}, null);
        //               if (account.moveToFirst() && sTaggingSupported.contains(mAccountsService.get(accountId)))
        //                  accountEntries.put(account.getLong(0), account.getString(1));
        //            }
        //            int size = accountEntries.size();
        //            if (size != 0) {
        //               final long[] accountIndexes = new long[size];
        //               final String[] accounts = new String[size];
        //               int i = 0;
        //               Iterator<Map.Entry<Long, String>> entries = accountEntries.entrySet().iterator();
        //               while (entries.hasNext()) {
        //                  Map.Entry<Long, String> entry = entries.next();
        //                  accountIndexes[i] = entry.getKey();
        //                  accounts[i++] = entry.getValue();
        //               }
        //               mDialog = (new AlertDialog.Builder(this))
        //                     .setTitle(R.string.accounts)
        //                     .setSingleChoiceItems(accounts, -1, new DialogInterface.OnClickListener() {
        //                        @Override
        //                        public void onClick(DialogInterface dialog, int which) {
        //                           selectFriends(accountIndexes[which]);
        //                           dialog.dismiss();
        //                        }
        //                     })
        //                     .setNegativeButton(android.R.string.cancel, new DialogInterface.OnClickListener() {
        //                        @Override
        //                        public void onClick(DialogInterface dialog, int which) {
        //                           dialog.dismiss();
        //                        }
        //                     })
        //                     .create();
        //               mDialog.show();
        //            } else
        //               unsupportedToast(sTaggingSupported);
        //         }
    } else if (itemId == R.id.menu_post_location) {
        LocationManager locationManager = (LocationManager) MyfeedleCreatePost.this
                .getSystemService(Context.LOCATION_SERVICE);
        Location location = locationManager.getLastKnownLocation(LocationManager.NETWORK_PROVIDER);
        if (location != null) {
            mLat = Double.toString(location.getLatitude());
            mLong = Double.toString(location.getLongitude());
            if (mAccountsService.size() == 1) {
                if (sLocationSupported.contains(mAccountsService.values().iterator().next()))
                    setLocation(mAccountsService.keySet().iterator().next());
                else
                    unsupportedToast(sLocationSupported);
            } else {
                // dialog to select an account
                Iterator<Long> accountIds = mAccountsService.keySet().iterator();
                HashMap<Long, String> accountEntries = new HashMap<Long, String>();
                while (accountIds.hasNext()) {
                    Long accountId = accountIds.next();
                    Cursor account = this.getContentResolver().query(Accounts.getContentUri(this),
                            new String[] { Accounts._ID, ACCOUNTS_QUERY }, Accounts._ID + "=?",
                            new String[] { Long.toString(accountId) }, null);
                    if (account.moveToFirst() && sLocationSupported.contains(mAccountsService.get(accountId)))
                        accountEntries.put(account.getLong(account.getColumnIndex(Accounts._ID)),
                                account.getString(account.getColumnIndex(Accounts.USERNAME)));
                }
                int size = accountEntries.size();
                if (size != 0) {
                    final long[] accountIndexes = new long[size];
                    final String[] accounts = new String[size];
                    int i = 0;
                    Iterator<Map.Entry<Long, String>> entries = accountEntries.entrySet().iterator();
                    while (entries.hasNext()) {
                        Map.Entry<Long, String> entry = entries.next();
                        accountIndexes[i] = entry.getKey();
                        accounts[i++] = entry.getValue();
                    }
                    mDialog = (new AlertDialog.Builder(this)).setTitle(R.string.accounts)
                            .setSingleChoiceItems(accounts, -1, new DialogInterface.OnClickListener() {
                                @Override
                                public void onClick(DialogInterface dialog, int which) {
                                    setLocation(accountIndexes[which]);
                                    dialog.dismiss();
                                }
                            })
                            .setNegativeButton(android.R.string.cancel, new DialogInterface.OnClickListener() {
                                @Override
                                public void onClick(DialogInterface dialog, int which) {
                                    dialog.dismiss();
                                }
                            }).create();
                    mDialog.show();
                } else
                    unsupportedToast(sLocationSupported);
            }
        } else
            (Toast.makeText(this, getString(R.string.location_unavailable), Toast.LENGTH_LONG)).show();
    }
    return super.onOptionsItemSelected(item);
}

From source file:com.dragon4.owo.ar_trace.ARCore.MixView.java

@Override
public void onCreate(Bundle savedInstanceState) {

    super.onCreate(savedInstanceState);

    DataSource.createIcons(getResources());

    try {//from ww  w.ja v a  2s . c  o m
        // ??
        final PowerManager pm = (PowerManager) getSystemService(Context.POWER_SERVICE);
        // ?    ?? ?
        this.mWakeLock = pm.newWakeLock(PowerManager.SCREEN_BRIGHT_WAKE_LOCK, "My Tag");
        // ?? 
        locationMgr = (LocationManager) getSystemService(Context.LOCATION_SERVICE);
        //  ?? . 2 ?? (1/1000s), 3 ?? (m)? ? 
        locationMgr.requestLocationUpdates(LocationManager.GPS_PROVIDER, 1000, 3, this);

        //orientation sensor 
        sensorMgr_ori = (SensorManager) getSystemService(Context.SENSOR_SERVICE);
        orientationSensor = sensorMgr_ori.getDefaultSensor(Sensor.TYPE_ORIENTATION);

        killOnError(); // ?  ?
        requestWindowFeature(Window.FEATURE_NO_TITLE); // ?   ? 

        //  ?? 
        FrameLayout frameLayout = new FrameLayout(this);

        //  ?    ?, ? 
        frameLayout.setMinimumWidth(3000);
        frameLayout.setPadding(10, 0, 10, 10);

        // ? ? ? ?? ?
        camScreen = new CameraSurface(this);
        augScreen = new AugmentedView(this);
        setContentView(camScreen); // ? ?? ?  ? 

        // ? ?? ? 
        addContentView(augScreen, new LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT));

        // ? ? ? ?   ?.
        // ? ?  ?  ?? ?  ?  ?
        addContentView(frameLayout, new FrameLayout.LayoutParams(LayoutParams.FILL_PARENT,
                LayoutParams.WRAP_CONTENT, Gravity.BOTTOM));

        topLayoutOnMixView = new TopLayoutOnMixView(this);
        RelativeLayout.LayoutParams params = new RelativeLayout.LayoutParams(
                ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.MATCH_PARENT);
        addContentView(topLayoutOnMixView.mainArView, params);

        // ? ? ? topLayoutOnMixView ?  ?
        handleIntent(getIntent()); // ?? 

        //  ? ? ?
        if (!isInited) {
            mixContext = new MixContext(this); // ? ?
            // ? ?
            mixContext.downloadManager = new DownloadManager(mixContext);

            //? ?  ? 
            navigator = new Navigator(mixContext, topLayoutOnMixView.naverFragment);

            // ? ? ?? ? ?
            dWindow = new PaintScreen();
            dataView = new DataView(mixContext);

            isInited = true; //   true

        }

        if (mixContext.isActualLocation() == false) {
            Toast.makeText(this, getString(DataView.CONNECTION_GPS_DIALOG_TEXT), Toast.LENGTH_LONG).show();
        }

    } catch (Exception ex) {
        doError(ex); //  ? ? 
    }

    //   ? 
    IntentFilter naviBraodFilter = new IntentFilter();
    naviBraodFilter.addAction("NAVI");
    registerReceiver(naviRecevicer, naviBraodFilter);
}

From source file:com.adwhirl.AdWhirlManager.java

public Location getLocation() {
    if (contextReference == null) {
        return null;
    }/*from  ww w.  j  av  a2 s . c o  m*/

    Context context = contextReference.get();
    if (context == null) {
        return null;
    }

    Location location = null;

    if (context.checkCallingOrSelfPermission(
            android.Manifest.permission.ACCESS_FINE_LOCATION) == PackageManager.PERMISSION_GRANTED) {
        LocationManager lm = (LocationManager) context.getSystemService(Context.LOCATION_SERVICE);
        location = lm.getLastKnownLocation(LocationManager.GPS_PROVIDER);
    } else if (context.checkCallingOrSelfPermission(
            android.Manifest.permission.ACCESS_COARSE_LOCATION) == PackageManager.PERMISSION_GRANTED) {
        LocationManager lm = (LocationManager) context.getSystemService(Context.LOCATION_SERVICE);
        location = lm.getLastKnownLocation(LocationManager.NETWORK_PROVIDER);
    }
    return location;
}

From source file:com.kll.collect.android.activities.FormEntryActivity.java

/** Called when the activity is first created. */
@Override//from   w  w w.jav  a 2  s . co  m
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

    // must be at the beginning of any activity that can be called from an
    // external intent
    try {
        Collect.createODKDirs();
    } catch (RuntimeException e) {
        createErrorDialog(e.getMessage(), EXIT);
        return;
    }
    Log.i("Activity", "Created");
    mSharedPreferences = PreferenceManager.getDefaultSharedPreferences(this);
    mSharedPreferences
            .registerOnSharedPreferenceChangeListener(new SharedPreferences.OnSharedPreferenceChangeListener() {
                @Override
                public void onSharedPreferenceChanged(SharedPreferences sharedPreferences, String key) {
                    compressImage = mSharedPreferences
                            .getBoolean(PreferencesActivity.KEY_ENABLE_IMAGE_COMPRESSION, false);
                }
            });
    setContentView(R.layout.form_entry);
    /*      setTitle(getString(R.string.app_name) + " > "
    + getString(R.string.loading_form));*/
    setTitle(getString(R.string.app_name));

    Log.i("Entry", "Form");
    mErrorMessage = null;
    //progressBar = (ProgressBar) findViewById(R.id.progress);
    //progressBar.setVisibility(ProgressBar.VISIBLE);
    //progressBar.setProgress(0);

    mBeenSwiped = false;
    mAlertDialog = null;
    mCurrentView = null;
    mInAnimation = null;
    mOutAnimation = null;
    mGestureDetector = new GestureDetector(this, this);
    mQuestionHolder = (LinearLayout) findViewById(R.id.questionholder);

    // get admin preference settings
    mAdminPreferences = getSharedPreferences(AdminPreferencesActivity.ADMIN_PREFERENCES, 0);

    mNextButton = (ImageButton) findViewById(R.id.form_forward_button);
    mNextButton.setOnClickListener(new OnClickListener() {
        @Override
        public void onClick(View v) {
            mBeenSwiped = true;
            showNextView();
        }
    });

    mBackButton = (ImageButton) findViewById(R.id.form_back_button);
    mBackButton.setOnClickListener(new OnClickListener() {
        @Override
        public void onClick(View v) {
            mBeenSwiped = true;
            showPreviousView();
        }
    });

    needLocation = mSharedPreferences.getBoolean(PreferencesActivity.KEY_GPS_FIX, false);
    if (needLocation) {

        mLocationManager = (LocationManager) getSystemService(Context.LOCATION_SERVICE);
        mLocationManager.requestLocationUpdates(LocationManager.GPS_PROVIDER, 5000, 5, this);
    }

    // Load JavaRosa modules. needed to restore forms.
    new XFormsModule().registerModule();

    // needed to override rms property manager
    org.javarosa.core.services.PropertyManager.setPropertyManager(new PropertyManager(getApplicationContext()));

    String startingXPath = null;
    String waitingXPath = null;
    String instancePath = null;
    Boolean newForm = true;
    if (savedInstanceState != null) {
        if (savedInstanceState.containsKey(KEY_FORMPATH)) {
            mFormPath = savedInstanceState.getString(KEY_FORMPATH);
        }
        if (savedInstanceState.containsKey(KEY_INSTANCEPATH)) {
            instancePath = savedInstanceState.getString(KEY_INSTANCEPATH);
        }
        if (savedInstanceState.containsKey(KEY_XPATH)) {
            startingXPath = savedInstanceState.getString(KEY_XPATH);
            Log.i(t, "startingXPath is: " + startingXPath);
        }
        if (savedInstanceState.containsKey(KEY_XPATH_WAITING_FOR_DATA)) {
            waitingXPath = savedInstanceState.getString(KEY_XPATH_WAITING_FOR_DATA);
            Log.i(t, "waitingXPath is: " + waitingXPath);
        }
        if (savedInstanceState.containsKey(NEWFORM)) {
            newForm = savedInstanceState.getBoolean(NEWFORM, true);
        }
        if (savedInstanceState.containsKey(KEY_ERROR)) {
            mErrorMessage = savedInstanceState.getString(KEY_ERROR);
        }
    }

    // If a parse error message is showing then nothing else is loaded
    // Dialogs mid form just disappear on rotation.
    if (mErrorMessage != null) {
        createErrorDialog(mErrorMessage, EXIT);
        return;
    }

    // Check to see if this is a screen flip or a new form load.
    Object data = getLastNonConfigurationInstance();
    if (data instanceof FormLoaderTask) {
        mFormLoaderTask = (FormLoaderTask) data;
    } else if (data instanceof SaveToDiskTask) {
        mSaveToDiskTask = (SaveToDiskTask) data;
    } else if (data == null) {
        if (!newForm) {
            if (Collect.getInstance().getFormController() != null) {
                refreshCurrentView();
            } else {
                Log.w(t, "Reloading form and restoring state.");
                // we need to launch the form loader to load the form
                // controller...
                mFormLoaderTask = new FormLoaderTask(instancePath, startingXPath, waitingXPath);
                Collect.getInstance().getActivityLogger().logAction(this, "formReloaded", mFormPath);
                // TODO: this doesn' work (dialog does not get removed):
                // showDialog(PROGRESS_DIALOG);
                // show dialog before we execute...
                Log.i("Loader", "Executing");
                mFormLoaderTask.execute(mFormPath);
            }
            return;
        }

        // Not a restart from a screen orientation change (or other).
        Collect.getInstance().setFormController(null);
        CompatibilityUtils.invalidateOptionsMenu(this);

        Intent intent = getIntent();
        if (intent != null) {
            Uri uri = intent.getData();

            if (getContentResolver().getType(uri).equals(InstanceColumns.CONTENT_ITEM_TYPE)) {
                // get the formId and version for this instance...
                String jrFormId = null;
                String jrVersion = null;
                {
                    Cursor instanceCursor = null;
                    try {
                        instanceCursor = getContentResolver().query(uri, null, null, null, null);
                        if (instanceCursor.getCount() != 1) {
                            this.createErrorDialog("Bad URI: " + uri, EXIT);
                            return;
                        } else {
                            instanceCursor.moveToFirst();
                            instancePath = instanceCursor.getString(
                                    instanceCursor.getColumnIndex(InstanceColumns.INSTANCE_FILE_PATH));
                            Collect.getInstance().getActivityLogger().logAction(this, "instanceLoaded",
                                    instancePath);

                            jrFormId = instanceCursor
                                    .getString(instanceCursor.getColumnIndex(InstanceColumns.JR_FORM_ID));
                            int idxJrVersion = instanceCursor.getColumnIndex(InstanceColumns.JR_VERSION);

                            jrVersion = instanceCursor.isNull(idxJrVersion) ? null
                                    : instanceCursor.getString(idxJrVersion);
                        }
                    } finally {
                        if (instanceCursor != null) {
                            instanceCursor.close();
                        }
                    }
                }

                String[] selectionArgs;
                String selection;

                if (jrVersion == null) {
                    selectionArgs = new String[] { jrFormId };
                    selection = FormsColumns.JR_FORM_ID + "=? AND " + FormsColumns.JR_VERSION + " IS NULL";
                } else {
                    selectionArgs = new String[] { jrFormId, jrVersion };
                    selection = FormsColumns.JR_FORM_ID + "=? AND " + FormsColumns.JR_VERSION + "=?";
                }

                {
                    Cursor formCursor = null;
                    try {
                        formCursor = getContentResolver().query(FormsColumns.CONTENT_URI, null, selection,
                                selectionArgs, null);
                        if (formCursor.getCount() == 1) {
                            formCursor.moveToFirst();
                            mFormPath = formCursor
                                    .getString(formCursor.getColumnIndex(FormsColumns.FORM_FILE_PATH));
                        } else if (formCursor.getCount() < 1) {
                            this.createErrorDialog(
                                    getString(R.string.parent_form_not_present, jrFormId)
                                            + ((jrVersion == null) ? ""
                                                    : "\n" + getString(R.string.version) + " " + jrVersion),
                                    EXIT);
                            return;
                        } else if (formCursor.getCount() > 1) {
                            // still take the first entry, but warn that
                            // there are multiple rows.
                            // user will need to hand-edit the SQLite
                            // database to fix it.
                            formCursor.moveToFirst();
                            mFormPath = formCursor
                                    .getString(formCursor.getColumnIndex(FormsColumns.FORM_FILE_PATH));
                            this.createErrorDialog(getString(R.string.survey_multiple_forms_error), EXIT);
                            return;
                        }
                    } finally {
                        if (formCursor != null) {
                            formCursor.close();
                        }
                    }
                }
            } else if (getContentResolver().getType(uri).equals(FormsColumns.CONTENT_ITEM_TYPE)) {
                Cursor c = null;
                try {
                    c = getContentResolver().query(uri, null, null, null, null);
                    if (c.getCount() != 1) {
                        this.createErrorDialog("Bad URI: " + uri, EXIT);
                        return;
                    } else {
                        c.moveToFirst();
                        mFormPath = c.getString(c.getColumnIndex(FormsColumns.FORM_FILE_PATH));
                        // This is the fill-blank-form code path.
                        // See if there is a savepoint for this form that
                        // has never been
                        // explicitly saved
                        // by the user. If there is, open this savepoint
                        // (resume this filled-in
                        // form).
                        // Savepoints for forms that were explicitly saved
                        // will be recovered
                        // when that
                        // explicitly saved instance is edited via
                        // edit-saved-form.
                        final String filePrefix = mFormPath.substring(mFormPath.lastIndexOf('/') + 1,
                                mFormPath.lastIndexOf('.')) + "_";
                        final String fileSuffix = ".xml.save";
                        File cacheDir = new File(Collect.CACHE_PATH);
                        File[] files = cacheDir.listFiles(new FileFilter() {
                            @Override
                            public boolean accept(File pathname) {
                                String name = pathname.getName();
                                return name.startsWith(filePrefix) && name.endsWith(fileSuffix);
                            }
                        });
                        // see if any of these savepoints are for a
                        // filled-in form that has never been
                        // explicitly saved by the user...
                        for (int i = 0; i < files.length; ++i) {
                            File candidate = files[i];
                            String instanceDirName = candidate.getName().substring(0,
                                    candidate.getName().length() - fileSuffix.length());
                            File instanceDir = new File(
                                    Collect.INSTANCES_PATH + File.separator + instanceDirName);
                            File instanceFile = new File(instanceDir, instanceDirName + ".xml");
                            if (instanceDir.exists() && instanceDir.isDirectory() && !instanceFile.exists()) {
                                // yes! -- use this savepoint file
                                instancePath = instanceFile.getAbsolutePath();
                                break;
                            }
                        }
                    }
                } finally {
                    if (c != null) {
                        c.close();
                    }
                }
            } else {
                Log.e(t, "unrecognized URI");
                this.createErrorDialog("Unrecognized URI: " + uri, EXIT);
                return;
            }

            mFormLoaderTask = new FormLoaderTask(instancePath, null, null);
            Collect.getInstance().getActivityLogger().logAction(this, "formLoaded", mFormPath);
            showDialog(PROGRESS_DIALOG);
            // show dialog before we execute...
            Log.i("Loader", "Executing");
            mFormLoaderTask.execute(mFormPath);
        }
    }

}