相关疑难解决方法(0)

如何让应用程序在后台运行?继续收集数据?

在底部更新

我编写了一个记录用户位置,当前速度,平均速度和最高速度的应用程序.我想知道如何使应用程序执行以下操作:

  1. 防止屏幕在屏幕上打开时关闭
  2. 如果用户打开另一个应用程序或返回主屏幕,接到电话等,应用程序应该继续收集数据(或者每次更新位置时将所有数据写入数据库会更好吗?并且可能有一个按钮表示何时开始和停止收集数据?)

这是我写的代码.(如果你愿意,可以随意使用它,如果你对如何改进它有任何建议,我对建设性批评持开放态度:D)

package Hartford.gps;

import java.math.BigDecimal;

import android.app.Activity;
import android.content.Context;
import android.location.Criteria;
import android.location.Location;
import android.location.LocationListener;
import android.location.LocationManager;
import android.os.Bundle;
import android.widget.TextView;

public class GPSMain extends Activity implements LocationListener {

LocationManager locationManager;
LocationListener locationListener;

//text views to display latitude and longitude
TextView latituteField;
TextView longitudeField;
TextView currentSpeedField;
TextView kmphSpeedField;
TextView avgSpeedField;
TextView avgKmphField;

//objects to store positional information
protected double lat;
protected double lon;

//objects to store values for current and average speed
protected double currentSpeed;
protected …
Run Code Online (Sandbox Code Playgroud)

database gps android

7
推荐指数
1
解决办法
2万
查看次数

标签 统计

android ×1

database ×1

gps ×1