android - Get a string value out of a thread -
i have string
variable, , set it's value inside thread, since it's using netwok operation.
how can access values stored in strings
?
public class homeactivity extends appcompatactivity { // initialize aws dynamodb client public static amazondynamodbclient ddbclient; public static dynamodbmapper mapper; public static aqua aqua; // app details public static string = "a"; public static string b; public static boolean c; public static string d; public static string e; public static string f; @override protected void oncreate(bundle savedinstancestate) { super.oncreate(savedinstancestate); setcontentview(r.layout.activity_home); // initialize amazon cognito credentials provider cognitocachingcredentialsprovider credentialsprovider = new cognitocachingcredentialsprovider( getapplicationcontext(), "******", // identity pool id regions.**** // region ); // initialize aws dynamodb ddbclient = new amazondynamodbclient(credentialsprovider); mapper = new dynamodbmapper(ddbclient); thread thread = new thread(new runnable() { @override public void run() { try { // app details aqua = mapper.load(aqua.class, a); b = aqua.getb(); c = aqua.getc(); d = aqua.getd(); e = aqua.gete(); f = aqua.getf(); } catch (exception e) { log.e("error", e.getmessage()); } } }); thread.start(); } }
use executorservice
, submit callable
(below assumes want data stored inside b,c,d,e,f):
executorservice exec = executors.newsinglethreadexecutor(); future<string[]> future = exec.submit(new callable<string[]>() { @override public string[] call() { try { // app details aqua = mapper.load(aqua.class, a); b = aqua.getb(); c = aqua.getc(); d = aqua.getd(); e = aqua.gete(); f = aqua.getf(); } catch (exception e) { log.e("error", e.getmessage()); } return new string[] {b, c, d, e, f}; } }); // ... b @ value[0], c @ value[1] string[] value = future.get();
Comments
Post a Comment