Starting activity with a new flag
How can I start activity with a new flag? I have 2 activities. One is main and other one I used for displaying database in ListView
. It consists of address and (latitude,longitude) values. I'm trying that开发者_如何转开发 whenever I click an item control should go to the main activity and show that (latitude,longitude) values there on map. I passed the (latitude,longitude) values in a bundle and wrote a set()
in main activity to set the (lat,lon) values. But the main activity is running in background. My code in the 2nd activity is:
Intent i1=new Intent(Display.this,Cortes.class);
Bundle b11=new Bundle();
b11.putDouble(q, b1);
b11.putDouble(r, c1);
//b11.putBoolean("flag", flag);
i1.putExtras(b11);
i1.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
startActivity(i1);
Here b1,c1 are (latitude,longitude) values and Cortes
is main activity and Display
is 2nd activity. My code in main activity is:
public void set()
{
bun=getIntent().getExtras();
q=bun.getDouble("q");
r=bun.getDouble("r");
GeoPoint new1=new GeoPoint((int)(q*1000000), (int)(r*10000000));
mc.setCenter(new1);
mapOverlays = mv.getOverlays();
OverlayItem overlayitem = new OverlayItem(new1, "New", "test1");
itemizedOverlay.addOverlay(overlayitem);
mapOverlays.add(itemizedOverlay);
mc.animateTo(new1);
mv.setSatellite(false);
mc.setCenter(new1);
mv.postInvalidate();
}
Is there any way to call set()
from 2nd activity? Or how should I call it when the main activity is called from 2nd activity? Also I want to start main activity with a new flag.
Make sure main activity flag is "singleTop".
Intent init = new Intent(this, MainActivity.class);
init.putExtra(Putwhatever you want to put);
init.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP );
startActivity(init);
override onNewIntent method in MainActivity. You will get intent "init" which will passed as a parameter to onNewIntent method.
there is no problem in starting the activity. In bundle you need to fetch values like this:
Bundle var_name = getIntent().getExtras().getBundle(key);
精彩评论