2013年9月18日星期三

[Android] Ask a question

thread android app development , I have lots of activity, each activity requires basic requests the server to get the data you want to get . The request takes the network are large, so do not be in the main thread of these operations , you need to open another thread , and Handler in conjunction.
My steps are:
1. Open Thread
2. requests a path to get json return value
3. parse json object and get back
4. notification handler operation is complete , let handler to do further processing
But now there is a problem in every activity , every request the network will need to do it the same steps , different only request the network path , calling different methods parse json, and return different Entity. I think there is no kind of way, you can put this thread is extracted, so that all activity shared , we only need to pass the appropriate path and want to get the Entity or what kind of value , we can get what we want. Which god there are ways to help me explain, thank you
------ Solution ---------------------------- ----------------

no association   
For example : I may login, need to request the network , the user information back to me one entity.   
For example, I get news list , the need to get another entity , or List , etc.  
man came packaged Network please block this function code , the results returned by each sub- activity to resolve . .
------ Solution ---------------------------------------- ----
I think so :
you are in the main thread creates a Handler object, you call a " thread class " to be made out of a MyThread, then MyThread constructor , passing ( " the appropriate path ", " want to get Entity "," just created Hanlder objects " ) , then json back, after you receive handled through Handler UI thread ~
------ Solution ----------- ---------------------------------
My idea is to put a network request class open thread in which access to resources such as initializing various parameters in the constructor handling
resolved in another class
various return your definition of a base class such as Result god of horses
then returns the result of different variety of inherited AResult BResult ...
then define the protocol returns the body plus the return type of keywords such as resul-type = A
so you get an A on press AResult parse this class definition to parse ( different results call different method resolution ) and use the value resolves to instantiate a AResult returned to the requesting activity
------ Solution ---------------------------------------- ----
the child threads are time-consuming to get ,
------ Solution ----------------------- ---------------------
write a public class specialized processing network links to get data, and then returns the results in a different Activity which can parse it.
------ Solution ---------------------------------------- ----
write an analytical data interfaces, each entity class needs to resolve its own data to implement this interface , because there are different entity, consider using generics. The main thread is unfit for large data to another driver threads, but the request must be the result of a callback function to handle , or will cause death linked to this App unresponsive phenomenon.
------ eference --------------------------------------- < br> write a parent class , inherit his every activity , or you can get hold public class
------ eference --------------------- ------------------

Well, I was this idea that my activity have a common parent class , but also need to inherit him, which is more easy to manage.
I need to know is how to extract such a public class . Pass a path argument because I can do it , but the return of the entity , how can I go to write ? Because I need to parse the thread inside the json, for example, I need to get this request entity classes A , B another request will need to return the entity classes , how to do ?
------ eference --------------------------------------- < br> ask for rescue , if there is way to accomplish this , correct me .
If there is no way to accomplish this , or you want to solve this issue , you can help me top.
we are forced to suffer programmer , thanks
------ eference ------------------------- --------------
A and B, the entity has no associated entities ?
------ eference --------------------------------------- < br>
no association
For example : I may login, need to request the network , the user information back to me one entity.
For example, I get news list , the need to get another entity , or List so
------ eference ------------------ ---------------------

no association     
For example : I may login, need to request the network , the user information back to me one entity.     
For example, I get news list , the need to get another entity , or List , etc.          
man came packaged Network please block this function code , the results returned by each sub- activity to resolve . .  
Well yes, I can only request the network to this package , you can get a return json, but some json be complex or large amount of data , parsing will be very time consuming, so I want to parse this one is also packaged into
------ eference ---------------------------------- -----

no association     
For example : I may login, need to request the network , the user information back to me one entity.     
For example, I get news list , the need to get another entity , or List , etc.          
man came packaged Network please block this function code , the results returned by each sub- activity to resolve . .  
But now it seems , I can not
------ eference --------------------------- ------------




I think the reason should be placed purebred json parsing doing , because sometimes we need to parse a large amount of data , or the complexity is relatively high, so if placed on the UI thread doing , probably because of serious and time-consuming problems, so I want to put the thread in the analytical method to do it.
------ eference --------------------------------------- < br>
  
     
  
I think the reason should be placed purebred json parsing doing , because sometimes we need to parse a large amount of data , or the complexity is relatively high, so if placed on the UI thread doing , probably because of serious and time-consuming problems, so I want to put the thread in the analytical method to do it.  
resolved individually without affecting ah you do not open the thread parsing and downloading together also possible
------ eference ---- -----------------------------------

my own solution , write their own callback , thank you help. ! ! !
------ eference --------------------------------------- < br>
my own solution , write your own callback function , thank you help. ! ! !  
LZ V5
------ eference --------------------------------- ------

yes, this idea is correct, but this result is not what I want , but if you parse than the larger case, if the UI thread is doing , may will be very time consuming , so I need a public class , but also in the child thread is analytic doing .
------ eference --------------------------------------- < br>
Well, I did, but do not need to use generics, because the child thread there is no practical use of the Entity . Thank you

没有评论:

发表评论