0

I am trying to implement an application which uses RESTFUL webservices.

I got my session id in my first activity. Now i need to maintain the session when i am navigating to other activities. Now I am getting RECEIVED AUTHENTICATION CHALLEGE IS NULL.

Can anyone help me?

I am passing the sessionid from first activity to second activity.

My second activity :

public class SetHome extends Activity {

String applicationId,sessionId;

    public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.home);
    System.out.println("Entered thissss");

    applicationId = getIntent().getExtras().getString("applicationId");
    System.out.println("Application id is--->" + applicationId);

                 sessionId = getIntent().getExtras().getString("sessionId");
    System.out.println("SessionId is--->" + sessionId);


    HttpConnectionRequest conn = new HttpConnectionRequest();
    conn.execute();


}

private class HttpConnectionRequest extends AsyncTask<Void, Void, Void> {

    @Override
    protected Void doInBackground(Void... params) {
        // TODO Auto-generated method stub
        String url = "url/application/"
                + applicationId;

        try {
            WebServiceClient client = new WebServiceClient();
            HashMap<String, String> hm = new HashMap<String, String>();
            hm.put("CONTENT-TYPE", "application/xml");
            hm.put("Accept", "application/xml");
            String sessionId;

            String applicationId;

            WebServiceResponse res = client.doGet(new URL(url), hm);
            int resCode = res.getResponseCode();

            String response = res.getResponseContent();

            System.out.println(res);
                             */

        } catch (Exception e) {
            e.printStackTrace();
        }

        return null;
    }

}

public static String getValue(String xpath_expr, String xml) {
    return BaseUtil.xpath_result(xpath_expr, xml);
}

public void relay(View v) {

}

public void tasks(View v) {

}

public void applications(View v) {

    HttpConnectionRequest conn = new HttpConnectionRequest();
    conn.execute();

}
}

Now I am getting Received authentication challenge is null.

DroidGirl
  • 231
  • 1
  • 2
  • 8
  • Please explain what need to be done of that session id in other activities in your app.. – Arpit Garg Feb 14 '12 at 18:58
  • how do i maintain session? I am not able to retreive data from webservices in the second activity . I am getting Received authentication challenge is null. exception – DroidGirl Feb 14 '12 at 19:10

2 Answers2

0

You can use many ways.two of them are:

  1. you can use Intent.putExtras.( or you can use Bundle and put that bundle inside Intent).
  2. You can use sharedPreferences to put data persistently ine first activity and you can access it in second activity.
  3. First point example is here
  4. Second point example is here
Community
  • 1
  • 1
Android Killer
  • 18,174
  • 13
  • 67
  • 90
0

I would recommend to you to create a class which extends Application. Make public variable there and then you can get that variable with MyApplicationClass app = (MyApplicationClass)getApplication(); app.myVariable; from any Activity. You would also need to put that classname in <application> tag in manifest. More info

zoki
  • 535
  • 1
  • 3
  • 17