I am building an app which monitors GPS location at 10 second intervals in a background thread and tests it against some criteria, and if the test is successful it then sends a message to a broadcast receiver. The following code for the receiver gets the the latitude and longitude from the background thread, and works fine just displaying the result in a toast.
package com.barney.gpstracking;
import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
import android.widget.Toast;
public class PosReceiver extends BroadcastReceiver {
double lat, lon;
String slat, slon;
@Override
public void onReceive(Context context, Intent intent) {
Bundle params = intent.getExtras();
if (params != null) {
lat = params.getDouble("lati");
slat = String.valueOf(lat);
lon = params.getDouble("long");
slon = String.valueOf(lon);
}
Toast.makeText(context, "Position is:" + lat + " " + lon, Toast.LENGTH_LONG).show();
}
}
However, if I replace the toast with a call to start another activity as follows:
lon = params.getDouble("long");
slon = String.valueOf(lon);
}
Intent goPop=new Intent(context,PopUpActivity.class);
context.startActivity(goPop);
}
}
then it compiles and installs on my device ok but I get a run-time error as soon as it tries to receive a broadcast. The PopUpActivity that I am trying to call works perfectly if I try calling it from elsewhere (e.g. from the main activity). I guess therefore that the goPop intent above is incorrect. I have looked at advice in response to similar questions, but I can't figure out the problem. Can anyone help me please?