我已閱讀關於此問題的許多帖子,但我似乎無法讓我的代碼等待,直到它找到聯繫人名稱,然後繼續並加載我的下一個活動。如果它是一個短的短信,它的工作正常,但如果它是一個特別長的短信它崩潰。請任何幫助。需要應用程序,直到一個過程完成,然後繼續
這是因爲以下建議問題的新代碼還是一樣
new LoaderAsyncTask().execute();
}
public class LoaderAsyncTask extends AsyncTask<Void, Void, Void> {
// Variables to pass data between doInBackground() and onPostExevute() here
protected Void doInBackground(Void... params) {
Uri uri = Uri.withAppendedPath(PhoneLookup.CONTENT_FILTER_URI,
Uri.encode(smsSender));
Cursor cursor = ((Context) contexts).getContentResolver().query(uri,
new String[] { PhoneLookup.DISPLAY_NAME, PhoneLookup._ID },
null, null, null);
contactId = "";
name="unknown";
if (cursor.moveToFirst()) {
do {
contactId = cursor.getString(cursor.getColumnIndex(PhoneLookup._ID));
name = cursor.getString(cursor.getColumnIndex(PhoneLookup.DISPLAY_NAME));
} while (cursor.moveToNext());
}
return null;
}
protected void onPostExecute(Void result) {
////////////////////////////////////
// start a new task before dying
intents.setClass((Context) contexts, SendSMSActivity.class);
intents.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
// pass Serializable object
intents.putExtra("PhoneNumber", smsSender);
intents.putExtra("smsBody", smsBody);
intents.putExtra("SmsMessageId", SmsMessageId);
intents.putExtra("contactId", contactId);
intents.putExtra("SenderName", name);
// start UI
((Context) contexts).startActivity(intents);
}
}
這可能有助於指定你在寫什麼語言.. – Alex
他正在一個Android應用程序,亞歷克斯 –