如何在android中每隔30秒将Geo-location的新数据插入到SQLite数据库中?

时间:2016-08-03 09:02:00

标签: android

    GeoInformation geoInformation = new GeoInformation(d,cellid,locationid,lon,lat,m,mn,address,Signalstrength,ipAddress,ttt,timestamp,carrier);
    Gson gson = new Gson();
    String jsonData = gson.toJson(geoInformation);
    Log.i("**",jsonData);
    Toast.makeText(MainActivity.this, jsonData, Toast.LENGTH_SHORT).show();
    Toast.makeText(MainActivity.this, jsonData, Toast.LENGTH_SHORT).show();
    geolocationtDbHelper = new GeolocationDbHelper(context);
    sqLiteDatabase = geolocationtDbHelper.getWritableDatabase();
    geolocationtDbHelper.addInformation(timeData, jsonData, sqLiteDatabase);
    Toast.makeText(getBaseContext(),"Data Saved", Toast.LENGTH_LONG).show();
    geolocationtDbHelper.close();

1 个答案:

答案 0 :(得分:-1)

Isha,我们在android中每30秒重复一次任务有很多解决办法: 所以你可以使用具有后延迟的android处理程序来完成它,它将在30秒后调用。

new Handler().post(new Runnable() {
            @Override
            public void run() {
                //code here which you need to repeat after 30 secs.
                Toast.makeText(MainActivity.this, "Call after 30 secs", Toast.LENGTH_SHORT).show();
                new Handler().postDelayed(this, 1000 * 30);
            }
        });

我希望它会对你有所帮助。 如果您想阅读有关Handler的信息,可以点击以下链接: https://developer.android.com/reference/android/os/Handler.html#postDelayed(java.lang.Runnable,长)