Football Fans: Download the 2012 Schedule App from Google Play!


Go Back   Android Forums > Android Development > Application Development

Application Development Dev Lounge for the Coder Folks



Reply
 
LinkBack Thread Tools
Old February 2nd, 2012, 03:45 AM   #1 (permalink)
New Member
 
Join Date: Feb 2012
Location: Indore
Posts: 7
 
Device(s):
Thanks: 0
Thanked 0 Times in 0 Posts
Default use handler in web service

public Handler serviceCallHnadler = new Handler() {
public void handleMessage(Message msg) {
if (calling_flag == 2 ) {
AllData.firstList=null;
AllData.firstList = (SearchResponse[]) msg.obj;
dialog.dismiss();
calling_flag = 0;
Intent i = new Intent(CLASSNAME.this, CLASS_NAME_List.class);
startActivity(i);
}

public void onClick(View v)
{
calling_flag = 2;
new runWebService();
}


class runWebService extends Thread {
ServiceCaller ser = new ServiceCaller();
public runWebService() {
this.start();
}

@Override
public void run() {
try{
super.run();
if(!checkInternetConnection())
{
Toast.makeText(CLASSNAME.this, "No Internet Connection", Toast.LENGTH_LONG).show();
}else
{

if (calling_flag == 2) {
try {
ser.getresult(serviceCallHnadler);
} catch (Exception e) {
e.printStackTrace();
Log.d("get string search result : ", e.toString());
}
}//if condition closed
}//else condition closed
// serviceCallHnadler.sendEmptyMessage(0);
}catch (Exception e) {

e.printStackTrace();
}
}//run method closed

}//class closed


///--------------Method Written in caller class---------
public void getresult(Handler resHandler) {

String urlparam = "search&searchstring=" + AllData.searchdata+"&lid="+ AllData.languagecode;
SearchResponse[] resColl = null;
Message msg = new Message();
try {
String temUrl = URLEncoder.encode(URL1 + urlparam);
String response1 = "";
HttpClient httpclient = new DefaultHttpClient();
HttpPost httppost = new HttpPost(URL1 + "search"+"&lid="+ AllData.languagecode);

try {

// Add your data
List<NameValuePair> nameValuePairs = new ArrayList<NameValuePair>(
1);
nameValuePairs.add(new BasicNameValuePair("searchstring",
AllData.searchdata));
httppost.setEntity(new UrlEncodedFormEntity(nameValuePairs));
// Execute HTTP Post Request
HttpResponse response = httpclient.execute(httppost);
response1 = inputStreamToString(response.getEntity()
.getContent());
} catch (ClientProtocolException e) {
// TODO Auto-generated catch block
} catch (IOException e) {
// TODO Auto-generated catch block
}

JSONObject rootObj = new JSONObject(response1); // rootObj ist jetzt
// ein dict
JSONArray posts = (JSONArray) rootObj.get("posts");
int count = posts.length();
resColl = new SearchResponse[count];
for (int j = 0; j < count; j++) {
JSONObject firstRoute = (JSONObject) posts.getJSONObject(j);
JSONObject legs = (JSONObject) firstRoute.get("post");
String test = (String) legs.get("uid");

resColl[j] = new SearchResponse(legs);
}

} catch (Exception e) {
e.getMessage();
// res
}
msg.obj = resColl;
resHandler.sendMessage(msg);
// return resColl;

}


///--------------SearchResponse.class---------

public class SearchResponse {

private String Uid;
private String UserName;
private String errorMsg = "";



SearchResponse(JSONObject jsobj) {
try {
this.Uid = jsobj.get("uid").toString();
this.UserName = URLDecoder.decode((String) jsobj.get("name"),
"UTF-8");
// this.errorMsg =

} catch (Exception e) {

e.printStackTrace();
}
}

public String getUid() {
return Uid;
}

public void setUid(String Uid) {
this.Uid = Uid;
}

public String getUserName() {
return UserName;
}

public void setUserName(String UserName) {
this.UserName = UserName;
}
public String getErrorMsg() {
return errorMsg;
}

public void setErrorMsg(String errorMsg) {
this.errorMsg = errorMsg;
}

}

zalani is offline  
Reply With Quote
Sponsors
Reply

Bookmarks


Go Back   Android Forums > Android Development > Application Development User CP
Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On




All times are GMT -5. The time now is 12:12 PM.
Powered by vBulletin® Version 3.8.7
Copyright ©2000 - 2012, vBulletin Solutions, Inc.
Custom vBulletin Skins by: Relivo