开发者

onBackPressed location update android

i have a problem. I have 2 MapActivitys. In first i display some places on the map and have i listView with that places. When i click on listView it opens second Map and display one place on map and under some info about that place. Update location is good, but when i press Back button it displays first activity with a location not updated. My question is how to update location in first activity when pressed back button in second??? This is what i have done:

@Override
public void onBackPressed() {
    Intent data = new Intent();     
    data.p开发者_运维问答utExtra("Latitude", location.getLatitude() );
    data.putExtra("Longitude", location.getLongitude());
    setResult(RESULT_OK,data);
    super.onBackPressed();

}
 @Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
    if(requestCode == request_Code){
        if(resultCode == RESULT_OK){
                            Location location = new Location(provider);
            location.setLatitude(data.getDoubleExtra("Latitude", 0));
            location.setLongitude(data.getDoubleExtra("Longitude", 0));
            listener.onLocationChanged(location);
        }
    }
    super.onActivityResult(requestCode, resultCode, data);
}

This is solution for my problem


In first activity,start second activity by startActivityForResult().Then implement onActivityResult() where update your location.


You can override onResume() using the following code:

@Override
protected void onResume() {
    super.onResume();
    // update your location here
}

This is called every time an Activity gets resumed - in your case it pauses when you go to the details view, and resumes when you go back.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜