0

This is my code:

ClipboardManager clipboard = (ClipboardManager) getSystemService(Context.CLIPBOARD_SERVICE);
ClipData clip = clipboard.getPrimaryClip();
if(clip!=null) {
    ClipData.Item item = clip.getItemAt(0);
    String text= item.getText().toString();
    Log.d("log_tag", "clipboard: "+text);
}
else {
    Log.d("log_tag", "clipboard empty");
}

The problem is, after restarting device, this code says "clipboard empty", even though there is some text in clipboard (And I can verify that by pasting it in other android programs). Then, when I copy something new into android clipboard, my code can see it again and the problem disappears completely!

What can be the reason for this strange behavior?

user273084
  • 151
  • 7
  • In which activity method you have written the coding for clip board? –  Mar 11 '16 at 12:27
  • Originally it is in a non-GUI thread but i run it via runOnUiThread. And I also tested this code directly in the main activity with the same results. – user273084 Mar 11 '16 at 14:18

0 Answers0