我现在正在开发地理定位应用程序,但更新的谷歌 API(谷歌地图 v2)真的很混乱。
问题是:当我点击button1(见代码)时,它成功地显示了地图。
但是,当我单击 Android 设备上的后退按钮时,它会立即杀死 APP 而不是关闭setContentView(R.layout.mapview);
所以我想在点击back
按钮后显示初始显示而不是杀死APP。
请帮忙:
MainActivity.java
public class MainActivity extends FragmentActivity {
LocationManager mLocMan;
String mProvider;
Location location;
Context context;
//double latitude, longitude;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
mLocMan = (LocationManager)getSystemService(Context.LOCATION_SERVICE);
mProvider = mLocMan.getBestProvider(new Criteria(), true);
LocationListener mListener = new Geocoord();
mLocMan.requestLocationUpdates(mLocMan.GPS_PROVIDER, 6000, 10, mListener);
//Button 0
final Button btn = (Button)findViewById(R.id.btn);
btn.setOnClickListener(new Button.OnClickListener() {
public void onClick(View v) {
//1st site
try{
EditText mgrs_site1 = (EditText)findViewById(R.id.editText1);
String site1 = mgrs_site1.getText().toString().toUpperCase();
............
}catch(Exception e){
Toast.makeText(MainActivity.this, "Please input valid Coordination!", Toast.LENGTH_SHORT).show();}//ends try-catch
}
}); //ends button0
//Button 1
Button btn1 = (Button)findViewById(R.id.btn1);
btn1.setOnClickListener(new Button.OnClickListener() {
public void onClick(View v) {
btn.performClick();
setContentView(R.layout.mapview);
//Intent intent = new Intent(MainActivity.this, MapView.class);
//startActivity(intent);
}//ends onClick
});
}//ends onCreate
}//ends Activity