如果我onReceive()
只用一个简单的 toast 运行我的方法,我的应用程序就会运行。但是当我尝试执行一个循环然后显示一个 toast 时,我的程序崩溃了。有没有说我不能在onReceive()
方法中执行循环?
@Override
public void onReceive(Context ctx, Intent intent) {
DBAdapter havetododb = new DBAdapter(ctx);
Cursor cursor = havetododb.fetchAllItems();
if (cursor.moveToFirst()) {
do {
String title = cursor.getString(cursor.getColumnIndex("item"));
Toast.makeText(ctx, title, Toast.LENGTH_LONG).show();
} while (cursor.moveToNext());
}
cursor.close();
}
我试图在我的 logcat 中搜索错误,但它似乎是空的。