I have an activity to check if the device id and the device name exist in the local database (sqlite) and when the device is already registered then I will pass to another Activity called ConnectToCostCenter The code of an activity is:
public class StartActivity extends Activity {
Handler handler = new Handler();
DBHandler dbHandler;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.start_activity);
dbHandler = new DBHandler(this);
handler.postDelayed(new Runnable() {
@Override
public void run() {
String DeviceId = Settings.Secure.getString(getContentResolver(), Settings.Secure.ANDROID_ID);
String DeviceName = Build.MODEL;
RegisterDevice cc = new RegisterDevice(DeviceId, DeviceName);
if (!dbHandler.getAllDevice().isEmpty() && (dbHandler.getAllDevice().contains(cc)) ){
final Intent mainIntent = new Intent(StartActivity.this, ConnectToCostCenter.class);
startActivity(mainIntent);
} else {
Intent intent = new Intent(StartActivity.this, CreateOrEditActivity.class);
startActivity(intent);
}
StartActivity.this.finish();
}
}, 3000);
}
}
and the ArrayList :
public ArrayList<RegisterDevice> getAllDevice() {
SQLiteDatabase db = this.getReadableDatabase();
ArrayList<RegisterDevice> activityList = null;
try{
activityList = new ArrayList<RegisterDevice>();
String QUERY = "SELECT * FROM "+DEVICE_TABLE_NAME;
Cursor cursor = db.rawQuery(QUERY, null);
if(!cursor.isLast())
{
while (cursor.moveToNext())
{
RegisterDevice activity = new RegisterDevice();
activity.setDeviceId(cursor.getString(0));
// activity.setCreated(cursor.getString(2));
// activity.setModified(cursor.getString(3));
activity.setDeviceName(cursor.getString(1));
activityList.add(activity);
}
}
db.close();
}catch (Exception e){
Log.e("error",e+"");
}
return activityList;
}
The problem is if the device is exist in the database then the activity CreateOrEditActivity appear instead of ConnectToCostCenter any help please??