Home > Net >  Setting wallpaper deletes my recyler view content
Setting wallpaper deletes my recyler view content

Time:08-07

I have created a simple app where I am using API to get wallpapers in the Recycler view. Now when I click on any item on the recycler view, I want to set it as a wallpaper. I am using Wallpapermanager class and Picasso to set wallpaper. Now the problem I am facing right now is that- once I click on any item in the recycler view, the wallpaper is set but it deletes my content on the recycler view. I am facing this problem in android 12 only. in the previous android version I did not face such a problem.

Initially everything is loaded fine as shown in image below Initially everything is loaded fine as shown in image below

once I click on the item of recycler view every thing goes away as shown in the below image enter image description here

Mainactivity.java

 @Override
    public void onitemclicked(int index) {  //recycler view on item click method
        WallpaperManager wallpaperManager = WallpaperManager.getInstance(MainActivity.this);
        Intent intent=new Intent(MainActivity.this,setwallpaper.class);
        intent.putExtra("url",index);
        //startActivity(intent);
        Picasso.get().load("https://images.unsplash.com/photo-1541336032412-2048a678540d?ixlib=rb-1.2.1&ixid=MnwxMjA3fDB8MHxleHBsb3JlLWZlZWR8NHx8fGVufDB8fHx8&auto=format&fit=crop&w=600&q=60")
                .into(new Target() {
                    @Override
                    public void onBitmapLoaded(Bitmap bitmap, Picasso.LoadedFrom from) {
                        try {
                            wallpaperManager.setBitmap(bitmap);
                            Toast.makeText(MainActivity.this, "done2", Toast.LENGTH_SHORT).show();
                        } catch (IOException e) {
                            e.printStackTrace();
                        }
                    }

                    @Override
                    public void onBitmapFailed(Exception e, Drawable errorDrawable) {

                    }

                    @Override
                    public void onPrepareLoad(Drawable placeHolderDrawable) {

                    }
                });

    }

log

2022-08-06 10:34:30.867 12222-14341/com.napps.wallpaper V/FA: Connecting to remote service
2022-08-06 10:34:30.874 12222-12222/com.napps.wallpaper I/oplus.android.OplusFrameworkFactoryImpl: get feature:IOplusDynamicVsyncFeature
2022-08-06 10:34:30.874 12222-12222/com.napps.wallpaper I/oplus.android.OplusFrameworkFactoryImpl: get feature:IOplusDynamicVsyncFeature
2022-08-06 10:34:30.874 12222-12222/com.napps.wallpaper I/oplus.android.OplusFrameworkFactoryImpl: get feature:IOplusDynamicVsyncFeature
2022-08-06 10:34:30.880 12222-12222/com.napps.wallpaper I/oplus.android.OplusFrameworkFactoryImpl: get feature:IOplusDynamicVsyncFeature
2022-08-06 10:34:30.881 12222-12222/com.napps.wallpaper I/oplus.android.OplusFrameworkFactoryImpl: get feature:IOplusDynamicVsyncFeature
2022-08-06 10:34:30.881 12222-12222/com.napps.wallpaper I/oplus.android.OplusFrameworkFactoryImpl: get feature:IOplusDynamicVsyncFeature
2022-08-06 10:34:30.892 12222-14341/com.napps.wallpaper V/FA: Activity paused, time: 61129465
2022-08-06 10:34:30.903 12222-12222/com.napps.wallpaper D/WindowManager: Add to mViews: DecorView@706f9c[MainActivity],pkg= com.napps.wallpaper
2022-08-06 10:34:30.909 12222-12222/com.napps.wallpaper D/ViewRootImpl[MainActivity]: hardware acceleration = true, sRendererEnabled = true, forceHwAccelerated = false
2022-08-06 10:34:30.922 12222-12222/com.napps.wallpaper I/oplus.android.OplusFrameworkFactoryImpl: get feature:IOplusDynamicVsyncFeature
2022-08-06 10:34:30.922 12222-12222/com.napps.wallpaper I/oplus.android.OplusFrameworkFactoryImpl: get feature:IOplusDynamicVsyncFeature
2022-08-06 10:34:30.922 12222-12222/com.napps.wallpaper I/oplus.android.OplusFrameworkFactoryImpl: get feature:IOplusDynamicVsyncFeature
2022-08-06 10:34:30.933 12222-12222/com.napps.wallpaper I/oplus.android.OplusFrameworkFactoryImpl: get feature:IOplusDynamicVsyncFeature
2022-08-06 10:34:30.933 12222-12222/com.napps.wallpaper I/oplus.android.OplusFrameworkFactoryImpl: get feature:IOplusDynamicVsyncFeature
2022-08-06 10:34:30.933 12222-12222/com.napps.wallpaper I/oplus.android.OplusFrameworkFactoryImpl: get feature:IOplusDynamicVsyncFeature
2022-08-06 10:34:30.950 12222-12222/com.napps.wallpaper D/WindowManager: Add to mViews: DecorView@aa2af19[MainActivity],pkg= com.napps.wallpaper
2022-08-06 10:34:30.951 12222-12222/com.napps.wallpaper D/ViewRootImpl[MainActivity]: hardware acceleration = true, sRendererEnabled = true, forceHwAccelerated = false
2022-08-06 10:34:30.955 12222-12222/com.napps.wallpaper I/Quality: Skipped: false 14 cost 157.77881 refreshRate 0 processName com.napps.wallpaper
2022-08-06 10:34:30.963 12222-12222/com.napps.wallpaper I/BufferQueueConsumer: [](id:2fbe00000003,api:0,p:-1,c:12222) connect: controlledByApp=false
2022-08-06 10:34:30.963 12222-12222/com.napps.wallpaper I/BLASTBufferQueue: [ViewRootImpl[MainActivity]#3] constructor()
2022-08-06 10:34:30.965 12222-12222/com.napps.wallpaper V/ZoomWindowDecorView: setLastReportedMergedConfiguration mZoomDisplayHeight: 2400 getDecorView.7368604
2022-08-06 10:34:30.966 12222-14346/com.napps.wallpaper I/BufferQueueProducer: [ViewRootImpl[MainActivity]#3(BLAST Consumer)3](id:2fbe00000003,api:1,p:12222,c:12222) connect: api=1 producerControlledByApp=true
2022-08-06 10:34:30.975 12222-14323/com.napps.wallpaper D/SurfaceComposerClient: VRR [FRTC] client handle [bufferId:18446744073709551615 framenumber:0] [ffffffff, ffffffff]
2022-08-06 10:34:30.984 12222-12222/com.napps.wallpaper I/BufferQueueConsumer: [](id:2fbe00000004,api:0,p:-1,c:12222) connect: controlledByApp=false
2022-08-06 10:34:30.984 12222-12222/com.napps.wallpaper I/BLASTBufferQueue: [ViewRootImpl[MainActivity]#4] constructor()
2022-08-06 10:34:30.985 12222-14341/com.napps.wallpaper V/FA: Connection attempt already in progress
2022-08-06 10:34:30.985 12222-14341/com.napps.wallpaper V/FA: Activity resumed, time: 61129622
2022-08-06 10:34:30.985 12222-12222/com.napps.wallpaper V/ZoomWindowDecorView: setLastReportedMergedConfiguration mZoomDisplayHeight: 2400 getDecorView.178433817
2022-08-06 10:34:30.987 12222-14341/com.napps.wallpaper V/FA: Connection attempt already in progress
2022-08-06 10:34:30.988 12222-12222/com.napps.wallpaper D/array size: array size is zero
2022-08-06 10:34:30.988 12222-12222/com.napps.wallpaper D/array size: array size is zero
2022-08-06 10:34:30.989 12222-14346/com.napps.wallpaper I/BufferQueueProducer: [ViewRootImpl[MainActivity]#4(BLAST Consumer)4](id:2fbe00000004,api:1,p:12222,c:12222) connect: api=1 producerControlledByApp=true
2022-08-06 10:34:31.020 12222-14323/com.napps.wallpaper D/SurfaceComposerClient: VRR [FRTC] client handle [bufferId:18446744073709551615 framenumber:0] [ffffffff, ffffffff]
2022-08-06 10:34:31.030 12222-12222/com.napps.wallpaper I/Quality: Skipped: false 5 cost 64.43697 refreshRate 0 processName com.napps.wallpaper
2022-08-06 10:34:31.033 12222-14346/com.napps.wallpaper E/BLASTBufferQueue: [ViewRootImpl[MainActivity]#3](f:0,a:2) setNextTransaction
2022-08-06 10:34:31.061 12222-12222/com.napps.wallpaper I/Quality: Skipped: false 2 cost 28.117373 refreshRate 0 processName com.napps.wallpaper
2022-08-06 10:34:31.066 12222-12222/com.napps.wallpaper E/Parcel: Reading a NULL string not supported here.
2022-08-06 10:34:31.068 12222-14341/com.napps.wallpaper D/FA: Connected to remote service
2022-08-06 10:34:31.071 12222-14341/com.napps.wallpaper V/FA: Processing queued up service tasks: 3
2022-08-06 10:34:31.352 12222-12222/com.napps.wallpaper D/seed0: 77
2022-08-06 10:34:31.352 12222-12222/com.napps.wallpaper D/initial length of array: 80
2022-08-06 10:34:31.352 12222-12222/com.napps.wallpaper D/OplusScrollToTopManager: unregisterGuidePopupDismissReceiverInSystemUI
2022-08-06 10:34:31.352 12222-12222/com.napps.wallpaper D/OplusScrollToTopManager: Receiver not registered: android.view.OplusScrollToTopManager$1@19f57f
2022-08-06 10:34:31.352 12222-12222/com.napps.wallpaper D/OplusScrollToTopManager: unregisterSystemUIBroadcastReceiver 
2022-08-06 10:34:31.353 12222-12222/com.napps.wallpaper D/OplusScrollToTopManager: java.lang.IllegalArgumentException: Receiver not registered: android.view.OplusScrollToTopManager$2@314694c
2022-08-06 10:34:31.353 12222-12222/com.napps.wallpaper V/ZoomWindowDecorView: removeZoomView
2022-08-06 10:34:31.354 12222-14346/com.napps.wallpaper I/BufferQueueProducer: [ViewRootImpl[MainActivity]#3(BLAST Consumer)3](id:2fbe00000003,api:1,p:12222,c:12222) disconnect: api 1
2022-08-06 10:34:31.354 12222-14346/com.napps.wallpaper E/BLASTBufferQueue: BLASTBufferItemConsumer::onDisconnect()
2022-08-06 10:34:31.355 12222-12222/com.napps.wallpaper D/View: [Warning] assignParent to null: this = DecorView@706f9c[MainActivity]
2022-08-06 10:34:31.370 12222-14323/com.napps.wallpaper I/BLASTBufferQueue: [ViewRootImpl[MainActivity]#3] destructor()
2022-08-06 10:34:31.370 12222-14323/com.napps.wallpaper I/BufferQueueConsumer: [ViewRootImpl[MainActivity]#3(BLAST Consumer)3](id:2fbe00000003,api:0,p:-1,c:12222) disconnect
2022-08-06 10:34:31.379 12222-14323/com.napps.wallpaper I/BLASTBufferQueue: releaseBufferCallbackThunk bufferId:52493090291733 framenumber:35 blastBufferQueue is dead
2022-08-06 10:34:36.102 12222-14341/com.napps.wallpaper V/FA: Inactivity, disconnecting from the service
2022-08-06 10:35:27.409 12222-14583/com.napps.wallpaper V/FA: Recording user engagement, ms: 56460
2022-08-06 10:35:27.410 12222-14583/com.napps.wallpaper V/FA: Connecting to remote service
2022-08-06 10:35:27.421 12222-14583/com.napps.wallpaper V/FA: Activity paused, time: 61186083
2022-08-06 10:35:27.423 12222-14346/com.napps.wallpaper I/BufferQueueProducer: [ViewRootImpl[MainActivity]#4(BLAST Consumer)4](id:2fbe00000004,api:1,p:12222,c:12222) disconnect: api 1
2022-08-06 10:35:27.425 12222-14346/com.napps.wallpaper E/BLASTBufferQueue: BLASTBufferItemConsumer::onDisconnect()
2022-08-06 10:35:27.434 12222-12222/com.napps.wallpaper I/BLASTBufferQueue: [ViewRootImpl[MainActivity]#4] destructor()
2022-08-06 10:35:27.434 12222-12222/com.napps.wallpaper I/BufferQueueConsumer: [ViewRootImpl[MainActivity]#4(BLAST Consumer)4](id:2fbe00000004,api:0,p:-1,c:12222) disconnect
2022-08-06 10:35:27.459 12222-12222/com.napps.wallpaper E/Parcel: Reading a NULL string not supported here.
2022-08-06 10:35:27.461 12222-14324/com.napps.wallpaper I/BLASTBufferQueue: releaseBufferCallbackThunk bufferId:52493090291741 framenumber:31 blastBufferQueue is dead
2022-08-06 10:35:27.464 12222-14583/com.napps.wallpaper V/FA: Connection attempt already in progress
2022-08-06 10:35:27.465 12222-14583/com.napps.wallpaper D/FA: Connected to remote service
2022-08-06 10:35:27.466 12222-14583/com.napps.wallpaper V/FA: Processing queued up service tasks: 2
2022-08-06 10:35:29.438 12222-14583/com.napps.wallpaper D/FA: Application going to the background
2022-08-06 10:35:29.472 12222-14583/com.napps.wallpaper V/FA: Activity resumed, time: 61188142
2022-08-06 10:35:29.479 12222-12222/com.napps.wallpaper I/BufferQueueConsumer: [](id:2fbe00000005,api:0,p:-1,c:12222) connect: controlledByApp=false
2022-08-06 10:35:29.479 12222-12222/com.napps.wallpaper I/BLASTBufferQueue: [ViewRootImpl[MainActivity]#5] constructor()
2022-08-06 10:35:29.480 12222-14346/com.napps.wallpaper I/BufferQueueProducer: [ViewRootImpl[MainActivity]#5(BLAST Consumer)5](id:2fbe00000005,api:1,p:12222,c:12222) connect: api=1 producerControlledByApp=true
2022-08-06 10:35:29.491 12222-14324/com.napps.wallpaper D/SurfaceComposerClient: VRR [FRTC] client handle [bufferId:18446744073709551615 framenumber:0] [ffffffff, ffffffff]
2022-08-06 10:35:34.188 12222-14583/com.napps.wallpaper V/FA: Recording user engagement, ms: 4717
2022-08-06 10:35:34.189 12222-14583/com.napps.wallpaper V/FA: Activity paused, time: 61192859
2022-08-06 10:35:34.197 12222-14346/com.napps.wallpaper I/BufferQueueProducer: [ViewRootImpl[MainActivity]#5(BLAST Consumer)5](id:2fbe00000005,api:1,p:12222,c:12222) disconnect: api 1
2022-08-06 10:35:34.200 12222-14346/com.napps.wallpaper E/BLASTBufferQueue: BLASTBufferItemConsumer::onDisconnect()
2022-08-06 10:35:34.205 12222-12222/com.napps.wallpaper I/BLASTBufferQueue: [ViewRootImpl[MainActivity]#5] destructor()
2022-08-06 10:35:34.205 12222-12222/com.napps.wallpaper I/BufferQueueConsumer: [ViewRootImpl[MainActivity]#5(BLAST Consumer)5](id:2fbe00000005,api:0,p:-1,c:12222) disconnect
2022-08-06 10:35:34.237 12222-14596/com.napps.wallpaper I/BLASTBufferQueue: releaseBufferCallbackThunk bufferId:52493090291747 framenumber:20 blastBufferQueue is dead
2022-08-06 10:35:34.989 12222-14583/com.napps.wallpaper V/FA: Activity resumed, time: 61193664
2022-08-06 10:35:35.004 12222-12222/com.napps.wallpaper I/BufferQueueConsumer: [](id:2fbe00000006,api:0,p:-1,c:12222) connect: controlledByApp=false
2022-08-06 10:35:35.004 12222-12222/com.napps.wallpaper I/BLASTBufferQueue: [ViewRootImpl[MainActivity]#6] constructor()
2022-08-06 10:35:35.005 12222-14346/com.napps.wallpaper I/BufferQueueProducer: [ViewRootImpl[MainActivity]#6(BLAST Consumer)6](id:2fbe00000006,api:1,p:12222,c:12222) connect: api=1 producerControlledByApp=true
2022-08-06 10:35:35.022 12222-14596/com.napps.wallpaper D/SurfaceComposerClient: VRR [FRTC] client handle [bufferId:18446744073709551615 framenumber:0] [ffffffff, ffffffff]
2022-08-06 10:35:39.998 12222-14583/com.napps.wallpaper V/FA: Inactivity, disconnecting from the service

CodePudding user response:

This is caused due to Material3 / MaterialYou theming.
All open app's Activities are recreated on a wallpaper change.

You cannot straight-forwardly avoid this but you can use the ViewModel & check for configuration changes by storing the previous Configuration object.

Example:

class AppViewModel : ViewModel() {

    private var configuration: Configuration? = null

    // this RecyclerView data will survive configuration changes
    private val itemsLiveData = MutableLiveData<List<RecyclerViewItem>>()

    fun getConfiguration(): Configuration? {
        return configuration
    }

    fun setConfiguration(config: Configuration) {
        if (configuration == null) configuration = config
    }

    fun getSavedRecyclerViewItems(): List<RecyclerViewItem> {
        val items = itemsLiveData.value ?: emptyList()
    }

    /* your other ViewModel methods */
}

In Activity:

private val viewModel: AppViewModel by viewModels()

init {
    lifecycleScope.launchWhenStarted {
        // configuration handling not required on pre 12 devices.
        if (Build.VERSION.SDK_INT < Build.VERSION_CODES.S) {
            return@launchWhenStarted
        }

        if (viewModel.getConfiguration() == null) {
            viewModel.setConfiguration(resources.configuration)
        } else {
            val savedItems = viewModel.getSavedRecyclerViewItems()
            if (savedItems.isNotEmpty()) recyclerAdapter.setData(savedItems)
        } 
    }
}

  • Related