title: Getting Execute before finishing the task Android
body: <p>Hi I'm running the Asynctask in my activity and getting the data from the server. In <code>onPostExecute </code> metod I'm inserting the data in Database now I want to pass those ids in two different fragments I'm passing the the ids by following code:</p>
  <pre><code>Bundle bundle = new Bundle();
      bundle.putStringArray(BConstant.TAXONOMY_TID, dbtids);
      bundle.putStringArray(BConstant.PRODUCT_CATEGORY_NAMES,
              dblistProCategory);
      ProductCategoryFragment.newInstance(bundle);
  
      // ProductDetailsFragment
      Bundle bundleForProductList = new Bundle();
      bundleForProductList
              .putStringArray(BConstant.TAXONOMY_TID, dbtids);
      bundleForProductList.putString(BConstant.WEB_SERVICES_COOKIES,
              cookie);
      bundleForProductList.putStringArray(
              BConstant.PRODUCT_CATEGORY_NAMES, dblistProCategory);
      ProductListFragment.newInstance(bundleForProductList);
  </code></pre>
  <p>But above lines of code get executed before the AsyncTask fininshed. but i have written this line <code>new CategoryFrag().execute();</code> above this code. what should i do.</p>
  <h3>Edited</h3>
  <pre><code>protected void onPostExecute(JSONArray result) {
          listItems = new ArrayList&lt;String&gt;();
          for (int i = 0; i &lt; result.length(); i++) {
              try {
                  listItems
                          .add(result.getJSONObject(i)
                                  .getString(BConstant.NAME_CONSTANT)
                                  .toString());
              } catch (Exception ex) {
                  ex.printStackTrace();
              }
          }
          listProCategory = listItems.toArray(new String[0]);
    returnsTID = saDatabaseHandler.getProductCategoryTID();
          for (int i = 0; i &lt; tids.length; i++) {
              if (!returnsTID.contains(tids[i])) {
                  saDatabaseHandler.insertProductCategoryData(
                          tids[i], listProCategory[i]);
                  
              }
          }
          getOfflineData();
    }
  </code></pre>
  <p><strong>LOGCAT:</strong></p>
  <pre><code>    02-02 11:41:00.451: E/AndroidRuntime(20901): FATAL EXCEPTION: main
      02-02 11:41:00.451: E/AndroidRuntime(20901): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.abc.xyz/com.abc.xyz.ProductListActivity}: java.lang.NullPointerException
      02-02 11:41:00.451: E/AndroidRuntime(20901):    at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2114)
      02-02 11:41:00.451: E/AndroidRuntime(20901):    at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2139)
      02-02 11:41:00.451: E/AndroidRuntime(20901):    at android.app.ActivityThread.access$700(ActivityThread.java:143)
      02-02 11:41:00.451: E/AndroidRuntime(20901):    at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1241)
      02-02 11:41:00.451: E/AndroidRuntime(20901):    at android.os.Handler.dispatchMessage(Handler.java:99)
      02-02 11 :41:00.451: E/AndroidRuntime(20901):   at android.os.Looper.loop(Looper.java:137)
      02-02 11:41:00.451: E/AndroidRuntime(20901):    at android.app.ActivityThread.main(ActivityThread.java:4960)
      02-02 11:41:00.451: E/AndroidRuntime(20901):    at java.lang.reflect.Method.invokeNative(Native Method)
      02-02 11:41:00.451: E/AndroidRuntime(20901):    at java.lang.reflect.Method.invoke(Method.java:511)
      02-02 11:41:00.451: E/AndroidRuntime(20901):    at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1038)
      02-02 11:41:00.451: E/AndroidRuntime(20901):    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:805)
      02-02 11:41:00.451: E/AndroidRuntime(20901):    at dalvik.system.NativeStart.main(Native Method)
      02-02 11:41:00.451: E/AndroidRuntime(20901): Caused by: java.lang.NullPointerException
      02-02 11:41:00.451: E/AndroidRuntime(20901):    at java.util.Arrays$ArrayList.&lt;init&gt;(Arrays.java:38)
      02-02 11:41:00.451: E/AndroidRuntime(20901):    at java.util.Arrays.asList(Arrays.java:154)
      02-02 11:41:00.451: E/AndroidRuntime(20901):    at android.widget.ArrayAdapter.&lt;init&gt;(ArrayAdapter.java:141)
      02-02 11:41:00.451: E/AndroidRuntime(20901):    at com.abc.xyz.ProductCategoryFragment$DisplayProductCategoryListArrayAdapter.&lt;init&gt;(ProductCategoryFragment.java:175)
      02-02 11:41:00.451: E/AndroidRuntime(20901):    at com.abc.xyz.ProductCategoryFragment.onActivityCreated(ProductCategoryFragment.java:113)
      02-02 11:41:00.451: E/AndroidRuntime(20901):    at android.app.FragmentManagerImpl.moveToState(FragmentManager.java:848)
      02-02 11:41:00.451: E/AndroidRuntime(20901):    at android.app.FragmentManagerImpl.moveToState(FragmentManager.java:1035)
      02-02 11:41:00.451: E/AndroidRuntime(20901):    at android.app.FragmentManagerImpl.moveToState(FragmentManager.java:1017)
      02-02 11:41:00.451: E/AndroidRuntime(20901):    at android.app.FragmentManagerImpl.dispatchActivityCreated(FragmentManager.java:1804)
      02-02 11:41:00.451: E/AndroidRuntime(20901):    at android.app.Activity.performCreate(Activity.java:5206)
      02-02 11:41:00.451: E/AndroidRuntime(20901):    at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1094)
      02-02 11:41:00.451: E/AndroidRuntime(20901):    at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2078)
      02-02 11:41:00.451: E/AndroidRuntime(20901):    ... 11 more
  </code></pre>