作者热门文章
- Java 双重比较
- java - 比较器与 Apache BeanComparator
- Objective-C 完成 block 导致额外的方法调用?
- database - RESTful URI 是否应该公开数据库主键?
我正在进行一项主要 Activity ,其中我有一个按钮,当按下此按钮时它会显示 map 。这非常有效。
但是当我按下后退键时,我再次进入我的主要 Activity ,现在当我再次按下 map 按钮时,它会显示整个世界地图。
我的意思是说它从头开始。
我怎样才能从 Back Stack 中完全删除我的 map Activity 并重新创建以根据需要再次显示 map ?
或者任何其他解决方案来做到这一点?
编辑:1
btn_find_atm.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View arg0) {
Intent intent = new Intent(NearByATM.this, Map.class);
startActivityForResult(intent, request_map);
}
});
编辑:2
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
if (isGooglePlayAvailable()) {
expld = new ExpandablePlaceListData();
criteria = new Criteria();
criteria.setAccuracy(Criteria.ACCURACY_FINE);
// Getting the service from context and giving to location_manager
location_manager = (LocationManager) getSystemService(LOCATION_SERVICE);
setContentView(R.layout.mapdemo);
placesTask = new PlacesTask();
getGoogleMap();
getUserLocation();
google_map.clear();
Toast.makeText(this, "Latitude:" + lat + " Longitude:" + lang,
Toast.LENGTH_LONG).show();
drawMarker();
sb = createUrl();
placesTask.execute(sb);
}
}
@Override
public void onBackPressed() {
super.onBackPressed();
Intent returnIntent = new Intent();
setResult(RESULT_OK, returnIntent);
this.finish();
}
编辑:3
private void getUserLocation() {
if (location_manager != null) {
provider = location_manager.getBestProvider(criteria, true);
location = location_manager.getLastKnownLocation(provider);
location_manager.requestLocationUpdates(provider,
Map.MIN_TIME_BW_UPDATES,
Map.MIN_DISTANCE_CHANGE_FOR_UPDATES, this);
if (location != null) {
lat = location.getLatitude();
lang = location.getLongitude();
} else {
Toast.makeText(Map.this, "Unable to idntify location",
Toast.LENGTH_LONG).show();
lat = -22.00000;
lang = 33.0000;
}
}
}
编辑:4
当我再次按下按钮加载 map 时,LogCat 会显示类似这些内容。
10-19 16:47:06.048: W/Trace(4887): Unexpected value from nativeGetEnabledTags: 0
10-19 16:47:06.086: I/SurfaceTexture(4887): [unnamed-4887-1](this:0x5fa6d608,api:0) detachFromContext
10-19 16:47:06.087: I/BufferQueue(4887): [unnamed-4887-1](this:0x610cd580,api:0) consumerDisconnect
10-19 16:47:06.088: I/BufferQueue(4887): [unnamed-4887-1](this:0x610cd580,api:0) ~BufferQueue
10-19 16:47:06.090: D/dalvikvm(4887): threadid=22: exiting
10-19 16:47:06.096: W/Trace(4887): Unexpected value from nativeGetEnabledTags: 0
10-19 16:47:06.097: D/dalvikvm(4887): threadid=22: bye!
10-19 16:47:08.782: W/Trace(4887): Unexpected value from nativeGetEnabledTags: 0
10-19 16:47:08.783: W/Trace(4887): Unexpected value from nativeGetEnabledTags: 0
10-19 16:47:08.785: W/Trace(4887): Unexpected value from nativeGetEnabledTags: 0
10-19 16:47:08.853: W/Trace(4887): Unexpected value from nativeGetEnabledTags: 0
10-19 16:47:08.853: W/Trace(4887): Unexpected value from nativeGetEnabledTags: 0
10-19 16:47:08.854: W/Trace(4887): Unexpected value from nativeGetEnabledTags: 0
10-19 16:47:08.864: W/Trace(4887): Unexpected value from nativeGetEnabledTags: 0
10-19 16:47:08.864: W/Trace(4887): Unexpected value from nativeGetEnabledTags: 0
10-19 16:47:08.865: W/Trace(4887): Unexpected value from nativeGetEnabledTags: 0
10-19 16:47:08.866: W/Trace(4887): Unexpected value from nativeGetEnabledTags: 0
10-19 16:47:08.866: W/Trace(4887): Unexpected value from nativeGetEnabledTags: 0
10-19 16:47:08.867: W/Trace(4887): Unexpected value from nativeGetEnabledTags: 0
10-19 16:47:08.874: W/Trace(4887): Unexpected value from nativeGetEnabledTags: 0
10-19 16:47:08.882: W/Trace(4887): Unexpected value from nativeGetEnabledTags: 0
最佳答案
最后我所做的是,
@Override
public void onBackPressed() {
super.onBackPressed();
google_map.clear();
location_manager.removeUpdates(this);
}
在 Activity 结果上,我从后台堆栈中删除了所有 Activity 。
Intent intent = new Intent(NearByATM.this, NearByATM.class);
intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TASK);
intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
startActivity(intent);
我也从历史记录中删除了主要 Activity 中的 list 文件,
android:excludeFromRecents="true"
android:noHistory="true"
关于android - 在 android 中加载谷歌地图的问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19462781/
我是一名优秀的程序员,十分优秀!