Calling a class when location change
<p>I need guide in calling a class to run after my location changed. Can anyone help me please. I think the problem is because of this codes: </p>

<pre><code>Intent i = new Intent(getApplicationContext(), CreateNewProduct.class);
startActivity(i);
</code></pre>

<p>This is the whole code: </p>

<p>(This is where I put some conditions when my location changes, also this is the part where I have to call the next class below.)</p>

<pre><code>class myLocationlistener implements LocationListener {
        @Override
        public void onLocationChanged(Location location) {
            if (location != null) {
                double pLong = location.getLongitude();
                double pLat = location.getLatitude();
                textLat.setText(Double.toString(pLat));
                textLong.setText(Double.toString(pLong));

                Intent i = new Intent(getApplicationContext(), CreateNewProduct.class);
                startActivity(i);
            }
        }
        @Override
        public void onProviderDisabled(String provider) {
        }
        @Override
        public void onProviderEnabled(String provider) {
        }
        @Override
        public void onStatusChanged(String provider, int status, Bundle extras) {
        }
    }
</code></pre>

<p>(Class to be called)</p>

<pre><code>class CreateNewProduct extends AsyncTask&lt;String, String, String&gt; {
        /**
         * Before starting background thread Show Progress Dialog
         * */
        @Override
        protected void onPreExecute() {
            super.onPreExecute();
            pDialog = new ProgressDialog(Sample.this);
            pDialog.setMessage("Sending Location");
            pDialog.setIndeterminate(false);
            pDialog.setCancelable(true);
            pDialog.show();
        }
        /**
         * Creating product
         * */
        protected String doInBackground(String... args) {
            String latitude = textLong.getText().toString();
            String longitude = textLat.getText().toString();
            // Building Parameters
            List&lt;NameValuePair&gt; params = new ArrayList&lt;NameValuePair&gt;();
            params.add(new BasicNameValuePair("latitude", latitude));
            params.add(new BasicNameValuePair("longitude", longitude));
            // getting JSON Object
            // Note that create product url accepts POST method
            JSONObject json = jsonParser.makeHttpRequest(url_create_product,
                    "POST", params);
            // check log cat fro response
            Log.d("Create Response", json.toString());
            // check for success tag
            try {
                int success = json.getInt(TAG_SUCCESS);
                if (success == 1) {
                    Toast.makeText(getBaseContext(), "Success",
                            Toast.LENGTH_SHORT).show();
                } else {
                    // failed to create product
                }
            } catch (JSONException e) {
                e.printStackTrace();
            }
            return null;
        }
        /**
         * After completing background task Dismiss the progress dialog
         * **/
        protected void onPostExecute(String file_url) {
            // dismiss the dialog once done
            pDialog.dismiss();
        }
    }
</code></pre>
