0

I have written an Asynctask that loads 5 feeds from different URLs, writes all to the same file (via the WriteFeed method shown below), and then loads an activity only based on the first feed.

However, I am getting a android.os.TransactionTooLargeException: data parcel size 1052800 bytes, even though all five feeds together only have 70 feed items overall. Please note that I am launching the next activity onPostExecute only with the parsed first feed, and yet I get this Exception during the AsyncTask. How to run these feeds parallelly? Please help.

private class AsyncLoadXMLFeed extends AsyncTask<String, Void, Void> {
        @Override
        protected Void doInBackground(String... params) {
            // Obtain feed
            String feedlink1, feedlink2, feedlink3, feedlink4, feedlink5;
            feedlink1=params[0];
            feedlink2=params[1];
            feedlink3=params[2];
            feedlink4=params[3];
            feedlink5=params[4];
            Log.e("MY LINK",feedlink1);
            try {
                DOMParser myParser = new DOMParser();
                feed = myParser.parseXml(feedlink1);
                feed2 = myParser.parseXml(feedlink2);
                feed3 = myParser.parseXml(feedlink3);
                feed4 = myParser.parseXml(feedlink4);
                feed5 = myParser.parseXml(feedlink5);
                if (feed != null && feed2 != null && feed3 != null && feed4 != null && feed5 != null) {
                    WriteFeed(feed);
                    WriteFeed(feed2);
                    WriteFeed(feed3);
                    WriteFeed(feed4);
                    WriteFeed(feed5);
                } else {
                    Log.e("FEED", "IS NULL");
                }
            } catch (Exception e) {
                e.printStackTrace();
            }
            return null;
        }

        @Override
        protected void onPostExecute(Void result) {
            super.onPostExecute(result);
            startNextActivity(feed);
        }
    }
Zac
  • 695
  • 1
  • 11
  • 34

2 Answers2

0

I think this is occurring because you are requesting 5 request at a time. You can make some delay with every request like below:

final Handler handler = new Handler();
handler.postDelayed(new Runnable() {
  @Override
  public void run() {
     feed = myParser.parseXml(feedlink1);
     if(feed!=null)
      WriteFeed(feed); 
  }
}, 1000);

Please let me know the result.

  • No this doesn't work - you are just adding a delay between the feeds, and look at onPostExecute, that's where I launch the next activity which uses the whole "feed" object. – Zac Dec 25 '16 at 05:41
  • This may help you: http://stackoverflow.com/questions/11451393/what-to-do-on-transactiontoolargeexception – MdFazlaRabbiOpu Dec 25 '16 at 05:45
0

This is not caused by the parsing, it should be that the next activity is called with its intent data exceeding 1 MB size. The feed object which you are passing to startNextActivity() should be the main culprit.

This might be a bit slower to the end user but should help resolve the error. Instead of calling AsyncLoadXMLFeed on the calling activity, call it in the onCreate() of the called activity and modify the async as follows.

private class AsyncLoadXMLFeed extends AsyncTask<String, Void, Void> {
FeedListener fl;
interface FeedListener{
   void onFeedParsed(Feed feed); //use appropriate class name
}
AsyncLoadXMLFeed(FeedListener fl){
   this.fl=fl;
}
@Override
protected Void doInBackground(String... params) {
   //No changes here
}
@Override
protected void onPostExecute(Void result) {
   super.onPostExecute(result);
   fl.onFeedParsed(feed); //the same feed object which was passed in startNewActivity.
}

on the activity which you are calling this async, you will get the feed object in onFeedParsed() then do the awesome stuff you plan to do with it.

Darshan Miskin
  • 844
  • 14
  • 25
  • Do you mean I have to create a new AsyncLoadXMLFeed class on the new activity, or modify the AsyncLoadXMLFeed class on the existing Splash activity? I don't understand how this fixes the issue... sorry. – Zac Dec 25 '16 at 05:39
  • modify the current one, but call it in the activity after the splash activity. The feed object which you were passing was passed as an intent data i suppose, which is what is being avoided in the above code. – Darshan Miskin Dec 25 '16 at 05:56