Answered step by step
Verified Expert Solution
Question
1 Approved Answer
Java/Android use of the AsyncTask. Consider whether the potential use of Async Task, as described below is appropriate or not, and answer whether it is
Java/Android use of the AsyncTask. Consider whether the potential use of Async Task, as described below is appropriate or not, and answer whether it is appropriate (True), or is not appropriate (False). The Java/ Android code snippet below may be useful in your consideration. It is not compiled code and is representative only, if there are errors, ignore them in answering this question. Assume this code may appear in an Android app nested within the main Activity. Assume that the main Activity includes methods which provide a data source for an ExpandableListView control on the Main Activity's view. private class NetworkRequestTask extends AsyncTask{... protected String doinBackground(String... to Sends) { ArrayList al = new ArrayList(); for (String aMsg: to Sends) { try { }catch(Exception ex) { ... }} String[] names = al.toArray(new String[0]); return names; } protected void on PostExecute(String[] result) { parent.aProperty = result.length; } True or False? A strength and primary advantage of the AsyncTask in Android is that it can be used in implement the data source methods for any UI control that requires an Adapter when information for that view must be obtained from the network. For example, to create a data source for an ExpandableListView control, the App developer must implement the method: public int getGroupCount(); which is a method of the BaseExpandableListAdapter class. The method should return the number of groups to be displayed in the control. The approach to using the AsyncTask can be described as follows. Suppose the number of groups is only obtainable through a network connection to a remote service. You should create an AsyncTask object (by calling its constructor) within the code of the getGroupCount method implementation. The Async Task would get the count from a remote server (JsonRPC, TCP/IP, or a Web Service) so that it can be returned directly by the AsyncTask's doinBackground method. That return value can then be returned by the getGroup Count method to the Expandable List View so it knows how many groups it should display. O True O False
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started