I have two activities one that send coordinates and one that recieves and drawing them.
I need that both of them will show GoogleMap... in the first activity i can see google map right away but then when i call to the second activity from BroadcastReceiver i just see blank white screen.
Thats my Second activity code:
public class NewActivity extends FragmentActivity {
GoogleMap googleMap;
String message;
String number;
double[] d = new double[4];
ArrayList<LatLng> points= new ArrayList<LatLng>() ;
@Override
public void onStart() {
super.onStart();
final LocalBroadcastManager localBroadcastManager =
LocalBroadcastManager.getInstance(this);
final IntentFilter localFilter = new IntentFilter();
localBroadcastManager.registerReceiver(localBroadcastReceiver, localFilter);
}
@Override
public void onStop() {
super.onStop();
final LocalBroadcastManager localBroadcastManager =
LocalBroadcastManager.getInstance(this);
// Make sure to unregister!!
localBroadcastManager.unregisterReceiver(localBroadcastReceiver);
}
BroadcastReceiver localBroadcastReceiver = new BroadcastReceiver()
{
@Override
public void onReceive(Context context, Intent intent)
{
setContentView(R.layout.ye);
SupportMapFragment fm = (SupportMapFragment) getSupportFragmentManager().findFragmentById(R.id.map);
googleMap = fm.getMap();
googleMap.setMyLocationEnabled(true);
message=intent.getStringExtra("message");
number=intent.getStringExtra("number");
int p=0;
Matcher m = Pattern.compile("(?!=\\d\\.\\d\\.)([\\d.]+)").matcher(message);
while(m.find())
{
double k = Double.parseDouble(m.group(1));
d[p]=k;
p++;
}
PolylineOptions polylineOptions = new PolylineOptions();
polylineOptions.color(Color.BLUE);
// Setting the width of the polyline
polylineOptions.width(6);
// Adding the taped point to the ArrayList
LatLng coordlocation = new LatLng(d[0], d[1]);
points.add(coordlocation);
LatLng coordlocation2 = new LatLng(d[2], d[3]);
points.add(coordlocation2);
// Setting points of polyline
polylineOptions.addAll(points);
googleMap.addPolyline(polylineOptions);
}
};
}
Note : I didnt registered the localBroadcastReceiver in the manifest file since i dont know if its neccessary.
I solved it by adding this:
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.ye);
}
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.