我用谷歌搜索了这个但没有成功,接缝对我来说很奇怪。
我正在构建一个简单的 GPS 应用程序,它使用 HttpRequest 发送坐标,尽管我注意到在最小化 UI 然后最大化时,它会运行相同 Activity 的副本。并在 HttpRequest 上加倍
private LocationManager locationManager;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_gps);
processExtraData();
}
private void processExtraData() {
locationManager = (LocationManager) getSystemService(Context.LOCATION_SERVICE);
locationManager.removeUpdates(this);
locationManager.requestLocationUpdates(LocationManager.GPS_PROVIDER,
10000, 5, this);
}
@Override
public void onLocationChanged(Location location) {
Bundle extras = getIntent().getExtras();
String driver_id = extras.getString("driverid");
String msg = "Driver:" + driver_id + "\nCurrent Location:\nLatitude: " + location.getLatitude()
+ "\nLongitude: " + location.getLongitude();
new HttpRequestTask(
new HttpRequest("https://www.autoflora.net/driver/gps.php?user_id=" + driver_id + "&latlong=" + location.getLatitude() + "*" + location.getLongitude(), HttpRequest.POST, "{ \"some\": \"data\" }"),
new HttpRequest.Handler() {
@Override
public void response(HttpResponse response) {
if (response.code == 200) {
Log.d(this.getClass().toString(), "Request successful!");
} else {
Log.e(this.getClass().toString(), "Request unsuccessful: " + response);
}
}
}).execute();
String s = calc.getText().toString();
calc.setText(s + "1")
TextView driver = (TextView) findViewById(R.id.driver);
driver.setText("" + driver_id);
TextView Longitude = (TextView) findViewById(R.id.longitude);
// Getting reference to TextView tv_latitude
TextView Latitude = (TextView) findViewById(R.id.latitude);
// Setting Current Longitude
Longitude.setText("Longitude:" + location.getLongitude());
// Setting Current Latitude
Latitude.setText("Latitude:" + location.getLatitude());
// Toast.makeText(getBaseContext(), msg, Toast.LENGTH_LONG).show();
}
最佳答案
noticed when minimising the UI then maximising
Android 上的 UI 既没有最小化
也没有最大化
。您显然通过启动器(这很可能是您的 maximizing
东西)再次启动 Activity ,这会创建您 Activity 的新实例。如果无论如何都只允许单个实例,则必须通过在 list 文件中的 Activity 声明中使用 android:launchMode
来设置系统。参见 docs here可能的选择。
关于java - Android 在最小化时复制 Activity,然后最大化,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41755618/