Results 1 to 10 of 10
Like Tree2Likes
  • 1 Post By Tolls
  • 1 Post By Tolls

Thread: How to pass a SoapObject from one Activity to another in an intent?

  1. #1
    Zarah is offline Senior Member
    Join Date
    Mar 2014
    Posts
    286
    Rep Power
    7

    Default How to pass a SoapObject from one Activity to another in an intent?

    I need to pass a SoapObject from one Activity to another, in an intent. Is that possible?

    I can't see it implementing Serializable, but it does implement `KvmSerializable` (although I don't know whatever it is).

  2. #2
    gimbal2 is offline Just a guy
    Join Date
    Jun 2013
    Location
    Netherlands
    Posts
    5,114
    Rep Power
    12

    Default Re: How to pass a SoapObject from one Activity to another in an intent?

    Well then you look at the javadoc of that interface and find out!

    KvmSerializable (KSoap 2 API)

    This interface does not extend Serializable, so no it is not going to work. You're probably better off using your own serializable beans and only at the very end when it is time to send the soap message do you turn it into a SoapObject.

    Is this perhaps a follow-up to your previous question about a LinkedHashMap being transformed into a HashMap?
    "Syntactic sugar causes cancer of the semicolon." -- Alan Perlis

  3. #3
    Zarah is offline Senior Member
    Join Date
    Mar 2014
    Posts
    286
    Rep Power
    7

    Default Re: How to pass a SoapObject from one Activity to another in an intent?

    I did see if it inherits from Serializable, rest I don't want to know what it does unless it serves my purpose. (Sorry, if that sounds like "wrong attitude").

    Is this perhaps a follow-up to your previous question about a LinkedHashMap being transformed into a HashMap?
    It's the same application I am working on, but this is a different issue. Actually I am consuming a SOAP based webservice, and I am parsing the response returned by it (which is a SoapObject) before returning it from (the doInBackground() of) my AsyncTask (in which I have called the web service):

    Java Code:
    protected List<ResponseParser.Entry> doInBackground(String... params) {
      ...
      return ResponseParser.parseResponse(responseSoapObject);
    }
    ResponseParser.parseResponse(responseSoapObject) returns an ArrayList. The data inside this ArrayList needs to be loaded to and displayed in a fragment.

    Now initially I was executing the AsyncTask inside loadInBackground() implementation of my custom AsyncTaskLoader, because inside that loadInBackground(), I was supposed to perform the query (to the data which needs to be loaded) (Reference: see doInBackground implementation, see doInBackground in the code in the end of page):

    Java Code:
    @Override
    	public List<Entry> loadInBackground() {
    		Log.i(TAG, "loadInBackground of ArrayListLoader called.");
    		
    		// TODO Perform the query here, and save the data in searchResultsList
                    soapResultsList = new MyTask().execute().get(60L, TimeUnit.SECONDS);
    
    		return soapResultsList;
    	}
    But it had some problems, and when I read up on them, I found out that execute() has to be called from the main thread, while doInBackground() is executed in the worker thread. SO I had to shift the execution of my task to the MainActivity, and from there I pass this to my fragment, from which it is passed to the adapter, as well as the loader:

    Java Code:
    public class ArrayListLoader extends AsyncTaskLoader<List<ResponseParser.Entry>> {
        private List<ResponseParser.Entry> soapResultsList = new ArrayList<>();
    
        public ArrayListLoader(Context context, Bundle responseBundle) {
            super(context);
            soapResultsList = (List<Entry>) responseBundle.getSerializable("tests.test.BUNDLE_KEY");
        }
    
        /***** (1) A TASK THAT PERFORMS THE ASYNCHRONOUS LOAD *********/
    
        @Override
        public List<Entry> loadInBackground() {
    
            // TODO Perform the query here, and save the data in soapResultsList
    
            return soapResultsList;
        }
        ...
    }
    So you see what is the point of having a loader when I am passing it the arraylist and simply then returning it back!

    So I think what I had to do was to execute the task from MainActivity, return the SoapObject from the web service response to the MainActivity, and then pass the SoapObject through to the loader's doInBackground() and then from there, call ResponseParser.parseResponse(responseSoapObject) from there, which returns the arrayList. That way I am doing this query in a worker thread. :-|

    But the new problem is passing the SoapObject from an Activity to another Activity to a fragment to an Adapter and a Loader.

  4. #4
    Tolls is offline Moderator
    Join Date
    Apr 2009
    Posts
    13,541
    Rep Power
    27

    Default Re: How to pass a SoapObject from one Activity to another in an intent?

    IMO the thing that is receiving the SoapObject should be the thing that is converting it into whatever local model you have representing that data.

    Passing a Soap object around is a bit like passing around a ResultSet in JDBC. It's just not something you should be doing.
    This is why "normal" web service layers convert the responses into domain objects almost as the first thing they do.
    gimbal2 likes this.
    Please do not ask for code as refusal often offends.

    ** This space for rent **

  5. #5
    Zarah is offline Senior Member
    Join Date
    Mar 2014
    Posts
    286
    Rep Power
    7

    Default Re: How to pass a SoapObject from one Activity to another in an intent?

    IMO the thing that is receiving the SoapObject should be the thing that is converting it into whatever local model you have representing that data.
    Yes, I agree. But then, what do people use the loaders for, when their data is being fetched in an AsyncTask, since we can't execute an AsyncTask in the loadInBackground() of the Loader.

    In my case, I think I need to get rid of the Loader altogether. It's not doing anything.

    It has just crossed my mind that probably my custom loader needed to be built on a simple Loader, and not an AsyncTaskLoader. But then isn't the "Asynchronous" loading of data the reason of the existence of loaders :-s
    Last edited by Zarah; 08-04-2015 at 11:52 AM.

  6. #6
    Tolls is offline Moderator
    Join Date
    Apr 2009
    Posts
    13,541
    Rep Power
    27

    Default Re: How to pass a SoapObject from one Activity to another in an intent?

    I don't know what the structure of your app is.
    It's hard to get a feel for it with only bits and pieces (and that's not a request for you to post it all...:)).

    From my position I would expect your Loader to be the thing that makes the web service call and builds your model based on the response.
    Please do not ask for code as refusal often offends.

    ** This space for rent **

  7. #7
    Zarah is offline Senior Member
    Join Date
    Mar 2014
    Posts
    286
    Rep Power
    7

    Default Re: How to pass a SoapObject from one Activity to another in an intent?

    From my position I would expect your Loader to be the thing that makes the web service call and builds your model based on the response.
    How come? I am sure you agree that the web service call needs to take place in an AsyncTask. And from the AsyncTask developer docs,

    There are a few threading rules that must be followed for this class to work properly:

    The AsyncTask class must be loaded on the UI thread. This is done automatically as of JELLY_BEAN.
    The task instance must be created on the UI thread.
    execute(Params...) must be invoked on the UI thread.
    ...

  8. #8
    Tolls is offline Moderator
    Join Date
    Apr 2009
    Posts
    13,541
    Rep Power
    27

    Default Re: How to pass a SoapObject from one Activity to another in an intent?

    The AsyncTaskLoader is an Async task, though.

    See the example for it here.
    The doInBackground loads the data and turns it into the model.
    The stuff around deliverResults is all about handing that data to whoever.
    Please do not ask for code as refusal often offends.

    ** This space for rent **

  9. #9
    Zarah is offline Senior Member
    Join Date
    Mar 2014
    Posts
    286
    Rep Power
    7

    Default Re: How to pass a SoapObject from one Activity to another in an intent?

    The AsyncTaskLoader is an Async task, though.

    See the example for it here.
    The doInBackground loads the data and turns it into the model.
    The stuff around deliverResults is all about handing that data to whoever.
    I was not thinking about it. Thank you so very much for this advice, I'll do it this way.

  10. #10
    Tolls is offline Moderator
    Join Date
    Apr 2009
    Posts
    13,541
    Rep Power
    27

    Default Re: How to pass a SoapObject from one Activity to another in an intent?

    The Android docs have several quite good examples of how they intended a particular thing to be used.
    I find them invaluable, especially since I don't work in Android regularly enough for anything to actually stick in my head.
    Zarah likes this.
    Please do not ask for code as refusal often offends.

    ** This space for rent **

Similar Threads

  1. is any way pass value to previous activity by sharedpreferences
    By raj.mscking@gmail.com in forum Android
    Replies: 4
    Last Post: 09-13-2013, 12:05 PM
  2. Intent & action
    By johnsonjp34 in forum Android
    Replies: 4
    Last Post: 11-07-2012, 07:55 PM
  3. Intent & action
    By johnsonjp34 in forum New To Java
    Replies: 0
    Last Post: 11-07-2012, 02:56 AM
  4. Replies: 0
    Last Post: 10-01-2011, 04:14 AM
  5. Replies: 1
    Last Post: 09-12-2011, 02:09 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •