0

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??

PRIYA PARASHAR
  • 777
  • 4
  • 15
ange
  • 1
  • 5
  • debug your code and check in your db whether or not it contains the row that you want to check or not – Anjali Sep 30 '16 at 12:02

1 Answers1

0

i think you getting little confusion to matching the condition, do some another way like you will iterate the array list and make condition inside the loop whether you can get true or false and make redirect the activity where you want.

parthi
  • 424
  • 1
  • 4
  • 16