我有一个活动来检查设备ID和设备名称是否存在于本地数据库(sqlite)中,当设备已经注册时,我将传递给另一个名为ConnectToCostCenter的Activity 活动代码为:
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);
}
}
和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;
}
问题是如果设备存在于数据库中,则会显示活动CreateOrEditActivity而不是ConnectToCostCenter 请帮忙吗?
答案 0 :(得分:0)
我认为你对匹配条件几乎没有混淆,做一些其他的方式,就像你将迭代数组列表并在循环中创建条件,无论你是否可以得到真或假,并将活动重定向到你想要的地方。