Note that there are some explanatory texts on larger screens.

plurals
  1. POAndroid - inserting into database after finishing AsyncTask
    primarykey
    data
    text
    <p>I am pretty much new in Java (&amp; android), hence I can't solve it with my limited knowledge despite searching extensively.</p> <p>In the code below, I want to get a JASONArray from a weblink through AsyncTask. After that I want to populate my database from the array data.</p> <p>To do that I created the RemoteConnectivity class where I can populate an ArrayList importdata with all the data from JASONArray. But the problem is, I cannot access my database class mylibmandbhandler from inside RemoteConnectivity class (I guess because that is not extended to Activity). And in ImportExport class, if I write the code to insert into database just after calling RemoteConnectivity().execute() [as in code below], it starts inserting before execution ends (very obvious because it is property of AsyncTask).</p> <p>Now, can anybody please guide me through this? Or any link please to understand the whole process (I am lost in at least 50 pages I read about it :( ).</p> <p>P.S. mylibmandbhandler is a Class I created (not activity) in my package src folder for my database operations.</p> <pre><code>public class ImportExport extends Activity { public void webimport(View v){ new RemoteConnectivity().execute(); // START OF ASYNCTASK //INSERT importdata INTO DATABASE AFTER EXECUTE mylibmandbhandler db = new mylibmandbhandler(this); for (String[] s : importdata){ db.addRecord(new mylibman(s)); } } final ArrayList&lt;String[]&gt; importdata = new ArrayList&lt;String[]&gt;(); private class RemoteConnectivity extends AsyncTask&lt;Void, Void, Void&gt; { @Override protected Void doInBackground(Void... arg0) { .................. .................. importdata.add(dataline); // POPULATE ARRAYLIST IMPORTDATA return null; } @Override protected void onPostExecute(Void result1) { // WHAT TO WRITE HERE } } } </code></pre>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload