0

I am sharing an image with text when I swipe right a RecyclerView item like below;

viewModel.shareUri.observe(viewLifecycleOwner,Observer{
        val shareIntent = Intent(Intent.ACTION_SEND);
        shareIntent.setType("image/png");
        shareIntent.addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION);
        shareIntent.putExtra(Intent.EXTRA_TEXT," "+requireContext().resources.getString(R.string.paylasimKitapAdText));
        shareIntent.putExtra(Intent.EXTRA_STREAM, it);
        startActivity(Intent.createChooser(shareIntent, view.context.resources.getString(R.string.shareLabel)));
        adapter?.notifyItemChanged(position);
    });

Share is opening and then I am canceling. After again when I share , chooser is multiplying? Is there any problem in this code?

emreturka
  • 846
  • 3
  • 18
  • 44
  • What do you mean by `chooser is multiplying`. Also can you add some more code so that anyone here can try and reproduce it? – gtxtreme Aug 27 '21 at 14:32
  • I mean that opening cancelation+1 share chooser after cancelation and again share. They are overlapping.When I press to back I noticed this – emreturka Aug 27 '21 at 14:38
  • Why is `notifyItemChanged` need in this case? – gtxtreme Aug 27 '21 at 14:39
  • Because of clearing canvas after right to left swipe. It is not important. – emreturka Aug 27 '21 at 14:47
  • Also it is behaving same with button click – emreturka Aug 27 '21 at 14:55
  • I feel you should add the other code too, the issue looks like something other than the code you have posted – gtxtreme Aug 27 '21 at 15:06
  • 1
    i think you need to check if value is right when value is right you call startActivity and clear the value viewmodel.isClicked.observe(viewLifecycleOwner, { if (it.value == true){ doSomething() viewmodel.isClicked.value = false } – Jalalkun Aug 27 '21 at 17:52
  • Yes @JalalKun.The reason is I don't hold and manage with state. – emreturka Aug 29 '21 at 18:45

0 Answers0