I'm developing a music player. Android Notification is using RemoteVeiw and it is related to Notification performance

Asked 2 years ago, Updated 2 years ago, 87 views

at Notification Use the setImageViewResource function of RemoteView to insert the album art image into the Notification. There is no problem, but it slows down little by little when a function of about 100 valleys(?) is called. There was no such problem when testing without the above function. Memory seems to be piling up, so what's the problem? The notificationManager.notify() function runs in the showNotify below.

    Glide.with(MusicPlayService.this)
            .load(ContentUris.withAppendedId(Constants.ARTWORK, CurrentPlayList.get().getList().get(CurrentPlayList.get().currentPosition).albumId))
            .asBitmap()
            .fallback(R.drawable.ic_launcher)
            .error(R.drawable.ic_launcher)
            .into(new SimpleTarget<Bitmap>() {
                @Override
                public void onResourceReady(Bitmap resource, GlideAnimation<? super Bitmap> glideAnimation) {
                    remoteViews.setImageViewBitmap(R.id.icon, resource);
                    remoteSmallViews.setImageViewBitmap(R.id.icon, resource);
                    showNotify();
                }
            });

android notification

2022-09-21 21:46

2 Answers

Thank you. It doesn't have much to do with Glide.

https://groups.google.com/forum/#!topic/android-developers/qQ4SV5wL7uM

The link above has been referenced.

There is no separate memory management part in RemoteView, so they want us to create a new RemoteView whenever the contents change, such as image invocation. It's been solved neatly.^

^


2022-09-21 21:46

Glide seems to have memory leak.

https://github.com/bumptech/glide/issues/616

onDestory() {
        Glide.get(this).clearMemory(); //  call this method manual 
}

It says that this will solve the problem in Activity running the code above.


2022-09-21 21:46

If you have any answers or tips


© 2024 OneMinuteCode. All rights reserved.