-
Notifications
You must be signed in to change notification settings - Fork 6.1k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Main thread assertion is redundant when using Glide with RemoteViews #310
Comments
Can you add a stack trace or a link to the code of the assertion you're referring to? Most of the assertions exist to prevent deadlock. That said, Targets are always called on the main thread, although you can start loads on a background thread. We could look in to changing that, but it might relatively straightforward to just change the remote views targets to post results to a background thread rather than trying to modify the framework. If you have a use case and want to make that change, I'd love to see a pull request. |
Sorry, there is no assertion, it has something to do with the Handler. Here is the relevant part of the stack trace.
|
Here is what happens when I try to use Glide with calling Looper.prepare() beforehand. Runnable runnable = new Runnable() {
@Override
public void run() {
Looper.prepare();
Glide.with(getApplicationContext())
.load(targetUrl)
.asBitmap()
.into(new NotificationTarget(
getApplicationContext(),
notificationView,
R.id.icon,
notification,
NOTIFICATION));
}
};
new Thread(runnable).start(); Stacktrace:
|
The Handler issue you mentioned was fixed in #295 and should be released in Glide 3.5 in the next couple of days. You can work around it (I think) by just calling The assertion in Results have to be handled on the main thread to avoid deadlock (with the exception of the API I mentioned above), so even getting around the assertion you mention won't really solve your problem. Again my inclination is that if setting the bitmap on the remote view is what is slow, you probably want to post it to a background thread inside NotificationTarget. The thread could for now just be a lazily initialized static variable. Have you added timing to see if you can find out what exactly is slow? You could also try traceview, which wouldn't require building from source. |
It indeed appears to be fixed. Using 3.5.2 now and I don't see the slow down. The issue can be closed. Sorry for not commenting on that earlier. |
I'm using NotificationTarget with Glide 3.4.0.
I'm updating a notification from a service running on a background thread. Because of the Glides assertion it has to run on the main thread. RemoteViews however don't require the main thread.
Because of the requirement, the whole phone becomes unresponsive for about one to two seconds. That's noticeable when you have a widget in a notification with a button like playing/pausing music.
Here is how I call Glide:
The text was updated successfully, but these errors were encountered: