1

How can I pass an big json-string between activities fast?

a) My Activity one look like this.

JsonDataTask jdt = new JsonDataTask(c);

AsyncTask<String, Integer, String> rdataJSON = jdt.execute("https://job.jobnet.dk/FindJobService/V1/Gateway.ashx/annonce?fritekst=akutjob&sortering=match");

try {   
   Intent i = new Intent(c, JoblistActivity.class);
   i.putExtra("rdataJSON", rdataJSON.get());
   startActivity(i);
} catch (InterruptedException e1) {
   e1.printStackTrace();
} catch (ExecutionException e1) {
   e1.printStackTrace();
}

b) Then Activity two below.

Intent intent = getIntent();
JobPosting_json = intent.getStringExtra("rdataJSON");

The problem is where the 'jdt.execute()' a.k.a json-string return too must data.. Then the 'getStringExtra("rdataJSON")' can´t holde the hule string..

2 Answers 2

1

You want to use Parcelable class to one activity to another, Refer http://developer.android.com/reference/android/os/Parcelable.html

Sign up to request clarification or add additional context in comments.

1 Comment

It is not good approach for big data. Parcelable allow to pass data no more than 1mb, but on some platforms no more than 512kb. It is not so many. If you trying to pass more than possible, your application will crash with TransactionTooLarge exception.
0

So two solutions:

  • or you cache the data in your first activity then get it in the second
  • or you do the request in the second activity

I usually go for the second option but it all depends on your requirements.

3 Comments

hmm if I use 2 option then the 'ProgressDialog' in the 'AsyncTask'-class do not show before swith to activity to.
well you can start the activity which start an asynctask with its progress dialog
Ok I just use option one, for this.. :)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.