Should I use Firebase Job Dispatcher
up vote
0
down vote
favorite
I have an android app that gets FCM Data messages (contains Image URL).
When Data Message is received in onMessageReceived()
I create a FirebaseJobDispatcher
and a Job, then schedule the Job for downloading and saving image in local storage dispatcher.mustSchedule(myJob)
.
The download and save image Job extends JobService
. When a Job is started I create a Thread to in which I download and save the Image, then I send a BroadcastReceiver
to the Activity so that it displays the new image from Local Storage in ImageView using Picasso (code below):
private String imageName = "image.jpg";
@Override
public boolean onStartJob(final JobParameters jobParameters) {
Log.d(TAG, "Update local storage content with new Image!");
Target target = new Target() {
@Override
public void onBitmapLoaded(final Bitmap bitmap, Picasso.LoadedFrom from) {
// Delegating work to a new Thread since it can be long task (downloading Image and storing it to local file system)
Thread storeImageThread = new Thread(new Runnable() {
@Override
public void run() {
// File file = new File(Environment.getExternalStorageDirectory().getPath() + "/" + imageName);
File file = new File(getApplicationContext().getFilesDir(), imageName);
try {
file.createNewFile();
FileOutputStream ostream = new FileOutputStream(file);
bitmap.compress(Bitmap.CompressFormat.JPEG, 75, ostream);
ostream.flush();
ostream.close();
} catch (IOException e) {
e.getLocalizedMessage();
}finally {
Intent intent = new Intent("com.example.SendBroadcast");
//intent.putExtra("imageURL", remoteMessage.getData().get("image"));
intent.setAction("com.example.SendBroadcast");
PendingIntent pendingIntent = PendingIntent.getActivity(getApplicationContext(), 0, intent,
PendingIntent.FLAG_UPDATE_CURRENT);
// sendBroadcast(intent);
sendOrderedBroadcast(intent,null);
//Tell the framework that the job has completed and does not need to be reschedule
jobFinished(jobParameters, true);
}
}
});
storeImageThread.start();
}
@Override
public void onBitmapFailed(Drawable errorDrawable) {
}
@Override
public void onPrepareLoad(Drawable placeHolderDrawable) {
}
};
Picasso.with(getApplicationContext())
.load(jobParameters.getExtras().getString("image"))
.into(target);
return true;
}
I am facing some problems with this architecture;
- The Job Service starts many times very late although I use setTrigger(Trigger.executionWindow(0, 0))
. So should I use a Firebase Job Dispatcher with Job Service for downloading and saving image in local storage? Is there any other alternative?
Is there more performance and efficient way to update the activity after finishing download and saving image?
I think Picasso uses separate Thread to download Image, so is my Thread use here correct?
Many times I am getting ARN dialog and app crashes. So is there a more performance architecture proposal for my purpose?
Thanks in advance for any help from experts
android firebase-cloud-messaging android-broadcastreceiver android-jobscheduler firebase-job-dispatcher
add a comment |
up vote
0
down vote
favorite
I have an android app that gets FCM Data messages (contains Image URL).
When Data Message is received in onMessageReceived()
I create a FirebaseJobDispatcher
and a Job, then schedule the Job for downloading and saving image in local storage dispatcher.mustSchedule(myJob)
.
The download and save image Job extends JobService
. When a Job is started I create a Thread to in which I download and save the Image, then I send a BroadcastReceiver
to the Activity so that it displays the new image from Local Storage in ImageView using Picasso (code below):
private String imageName = "image.jpg";
@Override
public boolean onStartJob(final JobParameters jobParameters) {
Log.d(TAG, "Update local storage content with new Image!");
Target target = new Target() {
@Override
public void onBitmapLoaded(final Bitmap bitmap, Picasso.LoadedFrom from) {
// Delegating work to a new Thread since it can be long task (downloading Image and storing it to local file system)
Thread storeImageThread = new Thread(new Runnable() {
@Override
public void run() {
// File file = new File(Environment.getExternalStorageDirectory().getPath() + "/" + imageName);
File file = new File(getApplicationContext().getFilesDir(), imageName);
try {
file.createNewFile();
FileOutputStream ostream = new FileOutputStream(file);
bitmap.compress(Bitmap.CompressFormat.JPEG, 75, ostream);
ostream.flush();
ostream.close();
} catch (IOException e) {
e.getLocalizedMessage();
}finally {
Intent intent = new Intent("com.example.SendBroadcast");
//intent.putExtra("imageURL", remoteMessage.getData().get("image"));
intent.setAction("com.example.SendBroadcast");
PendingIntent pendingIntent = PendingIntent.getActivity(getApplicationContext(), 0, intent,
PendingIntent.FLAG_UPDATE_CURRENT);
// sendBroadcast(intent);
sendOrderedBroadcast(intent,null);
//Tell the framework that the job has completed and does not need to be reschedule
jobFinished(jobParameters, true);
}
}
});
storeImageThread.start();
}
@Override
public void onBitmapFailed(Drawable errorDrawable) {
}
@Override
public void onPrepareLoad(Drawable placeHolderDrawable) {
}
};
Picasso.with(getApplicationContext())
.load(jobParameters.getExtras().getString("image"))
.into(target);
return true;
}
I am facing some problems with this architecture;
- The Job Service starts many times very late although I use setTrigger(Trigger.executionWindow(0, 0))
. So should I use a Firebase Job Dispatcher with Job Service for downloading and saving image in local storage? Is there any other alternative?
Is there more performance and efficient way to update the activity after finishing download and saving image?
I think Picasso uses separate Thread to download Image, so is my Thread use here correct?
Many times I am getting ARN dialog and app crashes. So is there a more performance architecture proposal for my purpose?
Thanks in advance for any help from experts
android firebase-cloud-messaging android-broadcastreceiver android-jobscheduler firebase-job-dispatcher
Is there any support from experts?
– Tigris Laesus
Nov 19 at 15:10
add a comment |
up vote
0
down vote
favorite
up vote
0
down vote
favorite
I have an android app that gets FCM Data messages (contains Image URL).
When Data Message is received in onMessageReceived()
I create a FirebaseJobDispatcher
and a Job, then schedule the Job for downloading and saving image in local storage dispatcher.mustSchedule(myJob)
.
The download and save image Job extends JobService
. When a Job is started I create a Thread to in which I download and save the Image, then I send a BroadcastReceiver
to the Activity so that it displays the new image from Local Storage in ImageView using Picasso (code below):
private String imageName = "image.jpg";
@Override
public boolean onStartJob(final JobParameters jobParameters) {
Log.d(TAG, "Update local storage content with new Image!");
Target target = new Target() {
@Override
public void onBitmapLoaded(final Bitmap bitmap, Picasso.LoadedFrom from) {
// Delegating work to a new Thread since it can be long task (downloading Image and storing it to local file system)
Thread storeImageThread = new Thread(new Runnable() {
@Override
public void run() {
// File file = new File(Environment.getExternalStorageDirectory().getPath() + "/" + imageName);
File file = new File(getApplicationContext().getFilesDir(), imageName);
try {
file.createNewFile();
FileOutputStream ostream = new FileOutputStream(file);
bitmap.compress(Bitmap.CompressFormat.JPEG, 75, ostream);
ostream.flush();
ostream.close();
} catch (IOException e) {
e.getLocalizedMessage();
}finally {
Intent intent = new Intent("com.example.SendBroadcast");
//intent.putExtra("imageURL", remoteMessage.getData().get("image"));
intent.setAction("com.example.SendBroadcast");
PendingIntent pendingIntent = PendingIntent.getActivity(getApplicationContext(), 0, intent,
PendingIntent.FLAG_UPDATE_CURRENT);
// sendBroadcast(intent);
sendOrderedBroadcast(intent,null);
//Tell the framework that the job has completed and does not need to be reschedule
jobFinished(jobParameters, true);
}
}
});
storeImageThread.start();
}
@Override
public void onBitmapFailed(Drawable errorDrawable) {
}
@Override
public void onPrepareLoad(Drawable placeHolderDrawable) {
}
};
Picasso.with(getApplicationContext())
.load(jobParameters.getExtras().getString("image"))
.into(target);
return true;
}
I am facing some problems with this architecture;
- The Job Service starts many times very late although I use setTrigger(Trigger.executionWindow(0, 0))
. So should I use a Firebase Job Dispatcher with Job Service for downloading and saving image in local storage? Is there any other alternative?
Is there more performance and efficient way to update the activity after finishing download and saving image?
I think Picasso uses separate Thread to download Image, so is my Thread use here correct?
Many times I am getting ARN dialog and app crashes. So is there a more performance architecture proposal for my purpose?
Thanks in advance for any help from experts
android firebase-cloud-messaging android-broadcastreceiver android-jobscheduler firebase-job-dispatcher
I have an android app that gets FCM Data messages (contains Image URL).
When Data Message is received in onMessageReceived()
I create a FirebaseJobDispatcher
and a Job, then schedule the Job for downloading and saving image in local storage dispatcher.mustSchedule(myJob)
.
The download and save image Job extends JobService
. When a Job is started I create a Thread to in which I download and save the Image, then I send a BroadcastReceiver
to the Activity so that it displays the new image from Local Storage in ImageView using Picasso (code below):
private String imageName = "image.jpg";
@Override
public boolean onStartJob(final JobParameters jobParameters) {
Log.d(TAG, "Update local storage content with new Image!");
Target target = new Target() {
@Override
public void onBitmapLoaded(final Bitmap bitmap, Picasso.LoadedFrom from) {
// Delegating work to a new Thread since it can be long task (downloading Image and storing it to local file system)
Thread storeImageThread = new Thread(new Runnable() {
@Override
public void run() {
// File file = new File(Environment.getExternalStorageDirectory().getPath() + "/" + imageName);
File file = new File(getApplicationContext().getFilesDir(), imageName);
try {
file.createNewFile();
FileOutputStream ostream = new FileOutputStream(file);
bitmap.compress(Bitmap.CompressFormat.JPEG, 75, ostream);
ostream.flush();
ostream.close();
} catch (IOException e) {
e.getLocalizedMessage();
}finally {
Intent intent = new Intent("com.example.SendBroadcast");
//intent.putExtra("imageURL", remoteMessage.getData().get("image"));
intent.setAction("com.example.SendBroadcast");
PendingIntent pendingIntent = PendingIntent.getActivity(getApplicationContext(), 0, intent,
PendingIntent.FLAG_UPDATE_CURRENT);
// sendBroadcast(intent);
sendOrderedBroadcast(intent,null);
//Tell the framework that the job has completed and does not need to be reschedule
jobFinished(jobParameters, true);
}
}
});
storeImageThread.start();
}
@Override
public void onBitmapFailed(Drawable errorDrawable) {
}
@Override
public void onPrepareLoad(Drawable placeHolderDrawable) {
}
};
Picasso.with(getApplicationContext())
.load(jobParameters.getExtras().getString("image"))
.into(target);
return true;
}
I am facing some problems with this architecture;
- The Job Service starts many times very late although I use setTrigger(Trigger.executionWindow(0, 0))
. So should I use a Firebase Job Dispatcher with Job Service for downloading and saving image in local storage? Is there any other alternative?
Is there more performance and efficient way to update the activity after finishing download and saving image?
I think Picasso uses separate Thread to download Image, so is my Thread use here correct?
Many times I am getting ARN dialog and app crashes. So is there a more performance architecture proposal for my purpose?
Thanks in advance for any help from experts
android firebase-cloud-messaging android-broadcastreceiver android-jobscheduler firebase-job-dispatcher
android firebase-cloud-messaging android-broadcastreceiver android-jobscheduler firebase-job-dispatcher
edited Nov 19 at 12:12
Ali
1,4192929
1,4192929
asked Nov 19 at 11:51
Tigris Laesus
4110
4110
Is there any support from experts?
– Tigris Laesus
Nov 19 at 15:10
add a comment |
Is there any support from experts?
– Tigris Laesus
Nov 19 at 15:10
Is there any support from experts?
– Tigris Laesus
Nov 19 at 15:10
Is there any support from experts?
– Tigris Laesus
Nov 19 at 15:10
add a comment |
1 Answer
1
active
oldest
votes
up vote
0
down vote
So should I use a Firebase Job Dispatcher with Job Service for
downloading and saving image in local storage?
Because your application is running state when onMessageReceived
is executed for FCM message. no need to use Firebase Job Dispatcher
Is there any other alternative?
Yes, use WorkManager for downloading image if app is not visible to user. save image in cache or sdcard and show it when app opened by user.
The Job Service starts many times very late although I
use setTrigger(Trigger.executionWindow(0, 0))
WorkManager providing options for checking task is finished or not before starting same task again.
OR
If app is already running then use normal service like IntentService
or Service
.
Thanks. I googled WorkManager, it seems that it uses JobScheduler service to schedule jobs else FirebaseJobDispatcher if JobScheduler is not supported. Is there a big defference by using WorkManager? Is it riggered immediately when Message received? Is it possible to use Background Threads instead?onMessageReceived()
Picasso starts a Thread for downloading Image from a URL andonBitmapLoaded()
I start a new Thread for saving the downloaded Image on file system. So when to stop the Thread? how to know Activity status (on or off) before sending Broadcast?
– Tigris Laesus
Nov 19 at 14:29
add a comment |
1 Answer
1
active
oldest
votes
1 Answer
1
active
oldest
votes
active
oldest
votes
active
oldest
votes
up vote
0
down vote
So should I use a Firebase Job Dispatcher with Job Service for
downloading and saving image in local storage?
Because your application is running state when onMessageReceived
is executed for FCM message. no need to use Firebase Job Dispatcher
Is there any other alternative?
Yes, use WorkManager for downloading image if app is not visible to user. save image in cache or sdcard and show it when app opened by user.
The Job Service starts many times very late although I
use setTrigger(Trigger.executionWindow(0, 0))
WorkManager providing options for checking task is finished or not before starting same task again.
OR
If app is already running then use normal service like IntentService
or Service
.
Thanks. I googled WorkManager, it seems that it uses JobScheduler service to schedule jobs else FirebaseJobDispatcher if JobScheduler is not supported. Is there a big defference by using WorkManager? Is it riggered immediately when Message received? Is it possible to use Background Threads instead?onMessageReceived()
Picasso starts a Thread for downloading Image from a URL andonBitmapLoaded()
I start a new Thread for saving the downloaded Image on file system. So when to stop the Thread? how to know Activity status (on or off) before sending Broadcast?
– Tigris Laesus
Nov 19 at 14:29
add a comment |
up vote
0
down vote
So should I use a Firebase Job Dispatcher with Job Service for
downloading and saving image in local storage?
Because your application is running state when onMessageReceived
is executed for FCM message. no need to use Firebase Job Dispatcher
Is there any other alternative?
Yes, use WorkManager for downloading image if app is not visible to user. save image in cache or sdcard and show it when app opened by user.
The Job Service starts many times very late although I
use setTrigger(Trigger.executionWindow(0, 0))
WorkManager providing options for checking task is finished or not before starting same task again.
OR
If app is already running then use normal service like IntentService
or Service
.
Thanks. I googled WorkManager, it seems that it uses JobScheduler service to schedule jobs else FirebaseJobDispatcher if JobScheduler is not supported. Is there a big defference by using WorkManager? Is it riggered immediately when Message received? Is it possible to use Background Threads instead?onMessageReceived()
Picasso starts a Thread for downloading Image from a URL andonBitmapLoaded()
I start a new Thread for saving the downloaded Image on file system. So when to stop the Thread? how to know Activity status (on or off) before sending Broadcast?
– Tigris Laesus
Nov 19 at 14:29
add a comment |
up vote
0
down vote
up vote
0
down vote
So should I use a Firebase Job Dispatcher with Job Service for
downloading and saving image in local storage?
Because your application is running state when onMessageReceived
is executed for FCM message. no need to use Firebase Job Dispatcher
Is there any other alternative?
Yes, use WorkManager for downloading image if app is not visible to user. save image in cache or sdcard and show it when app opened by user.
The Job Service starts many times very late although I
use setTrigger(Trigger.executionWindow(0, 0))
WorkManager providing options for checking task is finished or not before starting same task again.
OR
If app is already running then use normal service like IntentService
or Service
.
So should I use a Firebase Job Dispatcher with Job Service for
downloading and saving image in local storage?
Because your application is running state when onMessageReceived
is executed for FCM message. no need to use Firebase Job Dispatcher
Is there any other alternative?
Yes, use WorkManager for downloading image if app is not visible to user. save image in cache or sdcard and show it when app opened by user.
The Job Service starts many times very late although I
use setTrigger(Trigger.executionWindow(0, 0))
WorkManager providing options for checking task is finished or not before starting same task again.
OR
If app is already running then use normal service like IntentService
or Service
.
answered Nov 19 at 12:23
ρяσѕρєя K
113k26158187
113k26158187
Thanks. I googled WorkManager, it seems that it uses JobScheduler service to schedule jobs else FirebaseJobDispatcher if JobScheduler is not supported. Is there a big defference by using WorkManager? Is it riggered immediately when Message received? Is it possible to use Background Threads instead?onMessageReceived()
Picasso starts a Thread for downloading Image from a URL andonBitmapLoaded()
I start a new Thread for saving the downloaded Image on file system. So when to stop the Thread? how to know Activity status (on or off) before sending Broadcast?
– Tigris Laesus
Nov 19 at 14:29
add a comment |
Thanks. I googled WorkManager, it seems that it uses JobScheduler service to schedule jobs else FirebaseJobDispatcher if JobScheduler is not supported. Is there a big defference by using WorkManager? Is it riggered immediately when Message received? Is it possible to use Background Threads instead?onMessageReceived()
Picasso starts a Thread for downloading Image from a URL andonBitmapLoaded()
I start a new Thread for saving the downloaded Image on file system. So when to stop the Thread? how to know Activity status (on or off) before sending Broadcast?
– Tigris Laesus
Nov 19 at 14:29
Thanks. I googled WorkManager, it seems that it uses JobScheduler service to schedule jobs else FirebaseJobDispatcher if JobScheduler is not supported. Is there a big defference by using WorkManager? Is it riggered immediately when Message received? Is it possible to use Background Threads instead?
onMessageReceived()
Picasso starts a Thread for downloading Image from a URL and onBitmapLoaded()
I start a new Thread for saving the downloaded Image on file system. So when to stop the Thread? how to know Activity status (on or off) before sending Broadcast?– Tigris Laesus
Nov 19 at 14:29
Thanks. I googled WorkManager, it seems that it uses JobScheduler service to schedule jobs else FirebaseJobDispatcher if JobScheduler is not supported. Is there a big defference by using WorkManager? Is it riggered immediately when Message received? Is it possible to use Background Threads instead?
onMessageReceived()
Picasso starts a Thread for downloading Image from a URL and onBitmapLoaded()
I start a new Thread for saving the downloaded Image on file system. So when to stop the Thread? how to know Activity status (on or off) before sending Broadcast?– Tigris Laesus
Nov 19 at 14:29
add a comment |
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53374068%2fshould-i-use-firebase-job-dispatcher%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Is there any support from experts?
– Tigris Laesus
Nov 19 at 15:10