how to redirect my app to from one page to another page without loosing my id and password in android

StackOverflow https://stackoverflow.com/questions/22778777

  •  25-06-2023
  •  | 
  •  

質問

currently i am working on SMS project using our own SMS gateway. I used HttpClient to connect my home page of SMS gateway.successfully login but on next page I have to send SMS but when i call next post request old id and password are lost. I got home screen in response. Any one help me to get success message.

役に立ちましたか?

解決

You need to use the same httpClient to be able to control the session correctly.

Try these steps, referring to a generic LoginActivity

public static DefaultHttpClient httpClient;

Initialize it for the first time as follows.

URL url=new URL(urlToHit);
LoginScreen.httpClient = new DefaultHttpClient(); //LoginScreen is the name of the current Activity
HttpPost httppost = new HttpPost(url.toString());
HttpResponse response = LoginScreen.httpClient.execute(httppost);

Now for all further connections I used the same httpClient For example in the next activity.

URL url=new URL(urlToHit);
HttpPost httppost = new HttpPost(url.toString());
HttpResponse response = LoginScreen.httpClient.execute(httppost);

I haven't tested this, but I remember i had to face the same problem and i solved it storing the httpClient and using always that one.

Source: http://www.lightrains.com/blog/simple-tip-session-handling-android

他のヒント

What is the actual flux it should be doing? Where do you set this id and password? Do you have the server and the web in the same server? I think the question is a little undefined and the title could be very different from your real problem.

Check this in case it might help you Same-origin Policy

use Bundle for this,just like

Intent in = new Intent(current.this,destination.class);
Bundle bundle=new Bundle();
bundle.putString("ID", "3");    
bundle.putString("PASSWORD", "home");   
in.putExtras(bundle);
startActivity(in);

and you can get this in destination activity like

      Bundle selected = getIntent().getExtras();
      id= selected.getString("ID");
      password  = selected.getString("PASSWORD");
ライセンス: CC-BY-SA帰属
所属していません StackOverflow
scroll top