java - Setting Clipboard from non-ui thread -
issue: can't set clipboard non-ui background thread
how go around setting clipboard while app in background?
public class messages { public void setmessage(string text) { if (build.version.sdk_int < build.version_codes.honeycomb) { clipboardmanager clipboard = (clipboardmanager) getsystemservice(context.clipboard_service); clipboard.settext(text); } else { android.content.clipboardmanager clipboard = (android.content.clipboardmanager) getsystemservice(context.clipboard_service); clipdata clip = clipdata.newplaintext("newclip", text); clipboard.setprimaryclip(clip); } } }
error: cannot resolve getsystemservice(java.lang.string)
i tried multiple things solve issue, 1 of them is:
configuration class
/* made config class file so: */ public final class config { public static com.dysanix.official.mainactivity maincontext = null; } /* , put in oncreate of mainactivity: */ config.maincontext = this; /* * , using config.maincontext.getsystemservice() in other * class works, long ui visible on screen.. * tab out, code doesn't work anymore. */
i tried making "runnable" in mainactivity , call class, same issue: works, until tab out of app. calling method looped asynctask, know works because console keeps printing log message @ end of loop.
any appreciated!
error: cannot resolve getsystemservice(java.lang.string)
getsystemservice()
method on context
. pass context
setmessage()
method, or move method activity
, service
, or other context
implementation. then, call getsystemservice()
on context
.
i tried multiple things solve issue, 1 of them is:
do not put activity
in static field. not represent memory leak, activity
useless once destroyed, anyway.
issue: can't set clipboard non-ui background thread
there nothing related threads here.
Comments
Post a Comment