Commit 76366bc3 authored by Varun Patil's avatar Varun Patil

Do not create async task in background process

parent 57049bc9
......@@ -130,46 +130,37 @@ public class InstiAppFirebaseMessagingService extends FirebaseMessagingService {
final Context context, final String imageUrl, final String largeIconUrl,
final int notification_id, final NotificationCompat.Builder builder, final String content){
new AsyncTask<Void, Void, Bitmap[]>() {
@Override
protected Bitmap[] doInBackground(Void... params) {
try {
Bitmap image = null;
if (imageUrl != null) {
image = Picasso.get().load(imageUrl).get();
}
Bitmap largeIcon = null;
if (largeIconUrl != null) {
largeIcon = getCroppedBitmap(
Picasso.get().load(Constants.resizeImageUrl(largeIconUrl, 200)).get(), 200);
}
return new Bitmap[]{image, largeIcon};
} catch (IOException e) {
e.printStackTrace();
Bitmap[] bitmaps = null;
try {
Bitmap image = null;
if (imageUrl != null) {
image = Picasso.get().load(imageUrl).get();
}
return null;
}
@Override
protected void onPostExecute(Bitmap[] bitmaps) {
// Check if we loaded big image
if (bitmaps != null && bitmaps[0] != null) {
builder.setStyle(
new NotificationCompat.BigPictureStyle()
.bigPicture(bitmaps[0])
.setSummaryText(content)
);
Bitmap largeIcon = null;
if (largeIconUrl != null) {
largeIcon = getCroppedBitmap(
Picasso.get().load(Constants.resizeImageUrl(largeIconUrl, 200)).get(), 200);
}
bitmaps = new Bitmap[]{image, largeIcon};
} catch (IOException e) {
e.printStackTrace();
}
// Check if we loaded large icon
if (bitmaps != null && bitmaps[1] != null) {
builder.setLargeIcon(bitmaps[1]);
}
// Check if we loaded big image
if (bitmaps != null && bitmaps[0] != null) {
builder.setStyle(
new NotificationCompat.BigPictureStyle()
.bigPicture(bitmaps[0])
.setSummaryText(content)
);
}
showNotification(context, notification_id, builder.build());
super.onPostExecute(bitmaps);
// Check if we loaded large icon
if (bitmaps != null && bitmaps[1] != null) {
builder.setLargeIcon(bitmaps[1]);
}
}.execute();
showNotification(context, notification_id, builder.build());
}
/** Get circular center cropped bitmap */
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment