我想在用户关闭应用程序时清空服务器端的表以获取mac地址.因此,我从onDestroy()MainActivity中的方法启动IntentService类,但是没有启动Service .我已经在Manifest中注册了它.当我把代码放在onStop()服务中的onDestroy 启动时.
我不能在做这个工作onPause()或者onStop因为应用程序必须能够将数据记录(latitude, longitude, Speed, mac and time)在后台.
如果以这种方式不可能,我该如何管理它?
MainActivity中的onDestroy:
@Override
protected void onDestroy() {
super.onDestroy();
WifiManager wifiManager = (WifiManager) getSystemService(Context.WIFI_SERVICE);
WifiInfo wInfo = wifiManager.getConnectionInfo();
String macAddress = wInfo.getMacAddress();
JsonObject jsonObject = new JsonObject();
jsonObject.addProperty("mac", macAddress);
System.out.println("JsonObject" + jsonObject);
String json = jsonObject.toString();
Intent intent2 = new Intent(MainActivity.this,
ClearTable.class);
intent2.putExtra("json_mac", json);
startService(intent2);
Run Code Online (Sandbox Code Playgroud)
}
IntentService类:
public class ClearTable extends IntentService{
public ClearTable() {
super("IntentService");
}
@Override
protected void …Run Code Online (Sandbox Code Playgroud) 我正在尝试将数据插入arrivaltimes表中,但出现以下错误:
java.sql.SQLException:字段“id”没有默认值
stt.execute("CREATE TABLE IF NOT EXISTS stops"
+ "(stop_id INT(11) NOT NULL AUTO_INCREMENT PRIMARY KEY, "
+ " name varchar(30) NOT NULL, "
+ " route INT(11) NOT NULL, "
+ " lat double(10,6) NOT NULL, "
+ " longi double(10,6)NOT NULL) " );
stt.execute("INSERT INTO stops(name, route, lat, longi) values"
+ "('blabla', '1', '93.838039', '15.700440' ),"
+ "('backery', '9', '98.868863', '19.665438' )" );
stt.execute("CREATE TABLE IF NOT EXISTS arrivaltimes(id INT(11) NOT NULL PRIMARY KEY,"
+ " …Run Code Online (Sandbox Code Playgroud) 我试图让maven安装工作,但我总是得到这个错误
C:\ Windows\System32> mvn --version
错误:JAVA_HOME设置为无效目录.
JAVA_HOME ="C:\ Program Files\Java\jdk1.7.0_51;"
请在您的环境中设置JAVA_HOME变量以匹配Java安装的位置.
我知道错误说的是每件事,但我在这里尝试了一切.我有以下设置:
系统变量:
M2_HOME: C:\ Program Files\Apache Software Foundation\apache-maven-3.3.3
M2: %M2_HOME%\ bin
JAVA_HOME: C:\ Program Files\Java\jdk1.7.0_51
我添加了整条路径也许是有兴趣的人.请看一下最后一部分.
路径:
C:\Program Files\Java\jdk1.7.0_51\bin;C:\Windows\system32;C:\Windows;C:\Windows\System32\Wbem;C:\Windows\System32\WindowsPowerShell\v1.0\;C:\Program Files\MiKTeX 2.9\miktex\bin\x64\;C:\Program Files\TortoiseSVN\bin;C:\Program Files (x86)\Heroku\bin;C:\Program Files (x86)\git\cmd;%M2%;%JAVA_HOME%\bin;
Run Code Online (Sandbox Code Playgroud)
路径感兴趣部分:
%M2%;%JAVA_HOME%\bin;
Run Code Online (Sandbox Code Playgroud)
我已经通过删除它尝试了它,%JAVA_HOME%\bin;但它不起作用,因为我在路径开头的SDK安装有这条路径 C:\Program Files\Java\jdk1.7.0_51\bin
我试图将设置添加到用户变量,但它不起作用.
我onPrepareOptionsMenu()在Map活动中按下后退按钮后尝试在MainActivity中调用它,但是在创建一次后它没有被调用.根据文档,必须在显示菜单之前调用它.这种情况在调用onBackPressed()后是否有效?
准备要显示的屏幕标准选项菜单.每次显示菜单时都会调用此菜单.您可以使用此方法有效地启用/禁用项目或以其他方式动态修改内容.
我正在尝试构建一个字符串,11 11但我面临的问题是我得到start以下字符串,98 11而不是11 11.
我该如何解决这个问题?
我感谢任何帮助.
Character number = newName.charAt(2); //here number is 1
Character numberBefore = newName.charAt(1); //here numberBefore is 1
try (PrintWriter writer = new PrintWriter(path+File.separator+newName);
Scanner scanner = new Scanner(file)) {
boolean shouldPrint = false;
while (scanner.hasNextLine()) {
String line = scanner.nextLine();
if(numberBefore >0 ){
String start= number+number+" "+number+number; //here start is `98 11`
}
Run Code Online (Sandbox Code Playgroud) 我arrayList [5,8,13,18,19]从服务器获取,我想RadioGroup在xml文件中创建一个.选择可解决的项目后,我会将所选项目放入arrayList并在单击确定按钮后将查询发送到服务器.我怎样才能以编程方式创建RadioGroup?
我试过这个,但我不知道如何设置值RadioButton与ArrayList值.我怎样才能让tp工作?
private void createRadioButton(final ArrayList<Integer> items) {
final LinearLayout ll = (LinearLayout) findViewById(R.id.lila);
final ArrayList<RadioButton> rb = new ArrayList<RadioButton>();
final RadioGroup rg = new RadioGroup(this); // create the RadioGroup
rg.setOrientation(RadioGroup.HORIZONTAL);// or RadioGroup.VERTICAL
for (int i = 0; i < items.size(); i++) {
items.get(i) = new RadioButton(this);
}
}
Run Code Online (Sandbox Code Playgroud)