My Aysnc task not displaying next Activity using Intent. Also Where to call Intent if I want to switch to next Activity using Async task. below is my code.
btn_login.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View arg0) {
// TODO Auto-generated method stub
new Login_LC(getApplicationContext.this).execute();
countriesList();
}else {
}
}
});
private class Login_LC extends AsyncTask<String, Void, String> {
private ProgressDialog dialog;
String status = "";
Context ctx;
// String auth_token;
public Login_LC(Context context) {
dialog = new ProgressDialog(context);
}
@Override
protected void onPreExecute() {
this.dialog.setMessage("Please wait...");
this.dialog.setCancelable(false);
this.dialog.setCanceledOnTouchOutside(false);
this.dialog.show();
}
@Override
protected String doInBackground(String... urls) {
String response = "";
response = new SOAPService().authUser(urls[0], urls[1]);
System.out.println("RESPONSE= " + response);
status = new Auth_token().getStatus(response);
System.out.println("STATUS= " + status);
return status;
}
protected void onPostExecute(String s) {
System.out.println("S= " + s);
try{
JSONObject jsonObj = MainActivity.jsonObj.getJSONObject("data");
if(jsonObj!=null){
String req_Token = jsonObj.getString("request_token");
// req_token = req_Token;
new GetSubAccount(someclass.this, req_Token).execute(); //Async task Below called here
}
}
catch(Exception e){
System.out.print("----" +e);
}
Toast.makeText(someclass.this, "Login successfull", Toast.LENGTH_LONG).show();
try{
Intent loginIntent = new Intent(ctx, Dialpad.class);
ctx.startActivity(loginIntent);
}
catch(Exception e){
System.out.print("-----"+e);
}
}else if(s.equals("failed")){
Toast.makeText(someclass.this,"Wrong username/password!",Toast.LENGTH_SHORT).show();
}
else {
Toast.makeText(someclass.this, "Login failed!",
Toast.LENGTH_LONG).show();
}
}else{
if(dialog.isShowing()){
dialog.dismiss();
}
Toast.makeText(someclass.this,"No response from server!Please try again.",Toast.LENGTH_LONG).show();
}
}
}
SubAccount:
private class GetSubAccount extends AsyncTask<String, Void, String> {
JSONObject jsonObj;
String req_Token;
Vector numberList;
Context ctx;
private ProgressDialog dialog;
public GetSubAccount(Context context, String req_Token) {
// TODO Auto-generated constructor stub
dialog = new ProgressDialog(context);
this.req_Token = req_Token;
}
@Override
protected void onPreExecute() {
this.dialog.setMessage("Please wait...");
this.dialog.setCancelable(false);
this.dialog.setCanceledOnTouchOutside(false);
this.dialog.show();
}
@Override
protected String doInBackground(String... params) {
// TODO Auto-generated method stub
String response = null;
try{
response = new SOAPService().subAccount(req_Token);
jsonObj = new JSONObject(response);
}catch(Exception e){
System.out.print("Exception-----"+e);
}
return response;
}
@Override
protected void onPostExecute(String s) {
if(s!=null){
if (dialog.isShowing()) {
dialog.dismiss();
}
try{
if (s.equals("success")) {
try{
numberList = new Vector();
myNumbers = new Vector(); // this Vector used in next Activity
JSONObject jObj1 = jsonObj.getJSONObject("data");
JSONArray jArr = jObj1.getJSONArray("PhoneNumber");
for(int i=0;i<=jArr.length();i++){
numberList.add(jArr.getString(i));
System.out.print("number----- "+numberList);
JSONObject jObj2 = jArr.getJSONObject(i);
myNumbers.add(jObj2.getString("number"));
}
}
catch(Exception e){
System.out.print("Device Exception---" +e);
}
}
}
catch(Exception e){
System.out.print("------"+e);
}
}else{
}
}
}
// Intent not working? where to call Intent? Please help. thanks. :)