3

I'm trying to insert one row with id and timestamp into a sqlite database by clicking in my android app on virtual device.

private final String create_table = "CREATE TABLE clicks ( id INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL, timestamp INTEGER(4) NOT NULL);";

db.execSQL("insert into clicks(timestamp) values (strftime(\"%s\", CURRENT_TIME));");

When I run the app inserts three rows into the db instead of one row?

Any suggestion?

Here the MainActivity :

public class MainActivity extends AppCompatActivity {

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

    SQLite sqlite = new SQLite( this );
    sqlite.open();

    sqlite.insert();

    sqlite.close();

    System.exit(0);

}

}

When I close it, the app restarts twice. "System.exit(0)"

02-21 18:10:11.558 2232-2232/? I/art: System.exit called, status: 0
02-21 18:10:11.558 2232-2232/? I/AndroidRuntime: VM exiting with result code 0, cleanup skipped.
02-21 18:10:11.575 1203-1216/? I/ActivityManager: Process com.click.nautilus.click (pid 2232) has died
02-21 18:10:11.581 2246-2246/? I/art: Not late-enabling -Xcheck:jni (already on)
02-21 18:10:11.595 1203-1216/? I/ActivityManager: Start proc 2246:com.click.nautilus.click/u0a54 for activity com.click.nautilus.click/.MainActivity  
Phantômaxx
  • 37,901
  • 21
  • 84
  • 115

1 Answers1

1

I solved the issue. System.exit(0) is not recommended to finish an app.

Thank you again.

Finally the MainActivity looks like that:

protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

    SQLite sqlite = new SQLite(this);
    sqlite.open();

    sqlite.insert();

    sqlite.close();

    setResult(0);
    finish();

}

More info about closing app:

How to close Android application?

Community
  • 1
  • 1