private class MyTask extends AsyncTask<String, Integer, Integer> {
int number;
private String content = null;
private boolean error = false;
Context mContext;
int NOTIFICATION_ID = 1;
Notification mNotification;
NotificationManager mNotificationManager;
@Override
protected void onPreExecute() {
super.onPreExecute();
}
@Override
protected Boolean doInBackground(String... args) {
return true;
}
@Override
protected void onPostExecute(Integer result) {
if (response) {
//Build the notification using Notification.Builder
Notification.Builder builder = new Notification.Builder(mContext)
.setSmallIcon(R.mipmap.app_icon)
.setAutoCancel(true)
.setContentTitle(contentTitle)
.setContentText(contentText);
Intent intent = new Intent(mContext, CaptureActivity.class);
intent.setAction(Intent.ACTION_MAIN);
intent.addCategory(Intent.CATEGORY_LAUNCHER);
PendingIntent pendingIntent = PendingIntent.getActivity(mContext, 0,
intent, 0);
builder.setContentIntent(pendingIntent);
//Get current notification
mNotification = builder.getNotification();
//Show the notification
mNotificationManager.notify(NOTIFICATION_ID, mNotification);
}
}
Указанные коды являются частью моей асинтез. Поскольку процесс doinbackground будет немного длинным, я надеюсь, что позволит пользователю намереваться или перейти на другие страницы, чтобы им не приходилось слишком долго ждать и придерживаться этой активности. Есть ли способ до перейти к другому мероприятию, когда начало doinbackground? А также, если это возможно всплывает активность, когда doinbackgound завершен, это было бы здорово для меня. Большое спасибо.Переключиться на другую деятельность, когда выполняется AsyncTask
вы не можете начать деятельность на doInBackground и Offcourse вы оставили с onPostExecute сейчас. Там вы можете выполнить любую задачу пользовательского интерфейса. –
В onPostExecute задача была завершена doInBackground. Это не подходит для меня. – ng2b30