bonjour,
je voudrais passer un parametre entre 2 activity qui sont pas forcement lié entre elle je m'explique
A-->B-->C je veux passer le parametre de l'activité A et C j'utilise pour cela sharedpreference mais pour etre franc avec vous j'ai pas capté comment faire même en lisant la Doc donc si quelqu'un pouvais m'aider sa serais sympa
Activité A:
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
 
package com.example.ecommerce;
 
import org.ksoap2.SoapEnvelope;
import org.ksoap2.serialization.PropertyInfo;
import org.ksoap2.serialization.SoapObject;
import org.ksoap2.serialization.SoapPrimitive;
import org.ksoap2.serialization.SoapSerializationEnvelope;
import org.ksoap2.transport.HttpTransportSE;
 
 
 
import android.app.Activity;
 
import android.content.Intent;
import android.content.SharedPreferences;
import android.os.Bundle;
 
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.ArrayAdapter;
import android.widget.Button;
import android.widget.EditText;
import android.widget.Spinner;
import android.widget.TextView;
 
 
public class MainActivity extends Activity {
 
	EditText user,pass;
	Button connection;
	TextView inscription,result ;
	public Spinner spinner;
 
	private final String NAMESPACE = "http://ws.userlogin.com";
    private final String URL = "http://192.168.1.4:8085/Login/services/Login?wsdl";
    private final String SOAP_ACTION = "http://ws.userlogin.com/authentication";
    private final String METHOD_NAME = "authentication";
 
 
    private final String SOAP_ACTION1 = "http://ws.userlogin.com/authentification";
    private final String METHOD_NAME1 = "authentification";
    String spin1,str;
 
 
	@Override
		protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
 
		setContentView(R.layout.activity_main);
		spinner=(Spinner)findViewById(R.id.spin);
 
		ArrayAdapter<CharSequence> adapter = ArrayAdapter.createFromResource(this,R.array.Type,android.R.layout.simple_spinner_item);
		adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
		spinner.setAdapter(adapter);
		spin1 = spinner.getSelectedItem().toString();
 
		connection=(Button)findViewById(R.id.Connect);
		inscription=(TextView)findViewById(R.id.Inscription);
		inscription.setOnClickListener(new OnClickListener() {
 
			@Override
			public void onClick(View v) {
				Intent i=new Intent(MainActivity.this,Inscription.class);
			startActivity(i);	
			}
		});
 
		connection.setOnClickListener(new OnClickListener() {
 
			@Override
			public void onClick(View v) {
				spin1 = spinner.getSelectedItem().toString();
				if (spin1.equals("Vendeur")){		
					loginAction();
					Intent j=new Intent(MainActivity.this,Accueil_Vendeur.class);
					startActivity(j); 
 
		  }
			else{
					loginAction1();
 
				Intent j=new Intent(MainActivity.this,Accueil.class);
 
					startActivity(j);
 
 
			}
 
 
   }
  });
    }
 
 
    private void loginAction() {
 
    	new Thread(new Runnable() {
 
			@Override
			public void run() {
				 SoapObject request = new SoapObject(NAMESPACE, METHOD_NAME);
 
			     user=(EditText)findViewById(R.id.use_er);
					String u=user.getText().toString();
					pass=(EditText)findViewById(R.id.Pass);
 
					String p=pass.getText().toString();
			      //Pass value for userName variable of the web service
			        PropertyInfo unameProp =new PropertyInfo();
			        unameProp.setName("userName");//Define the variable name in the web service method
			        unameProp.setValue(u);//set value for userName variable
			        unameProp.setType(String.class);//Define the type of the variable
			        request.addProperty(unameProp);//Pass properties to the variable
 
			      //Pass value for Password variable of the web service
			        PropertyInfo passwordProp =new PropertyInfo();
			        passwordProp.setName("password");
			        passwordProp.setValue(p);
			        passwordProp.setType(String.class);
			        request.addProperty(passwordProp);
 
			        SoapSerializationEnvelope envelope = new SoapSerializationEnvelope(SoapEnvelope.VER11);
			        envelope.setOutputSoapObject(request);
			        HttpTransportSE androidHttpTransport = new HttpTransportSE(URL);
 
			        try{
			            androidHttpTransport.call(SOAP_ACTION, envelope);
			               SoapPrimitive response = (SoapPrimitive)envelope.getResponse();
			            str=response.toString(); 
 
 
			        }
			        catch(Exception e){
 
			        }
			        runOnUiThread(new Runnable(){
			        	public void run(){
			        		 result = (TextView) findViewById(R.id.textView5);
				               result.setText(str);
 
			        	}
			        });
 
			}
 
 
		}).start();
 
 
}
 
    private void loginAction1() {
 
    	new Thread(new Runnable() {
 
			@Override
			public void run() {
				 SoapObject request = new SoapObject(NAMESPACE, METHOD_NAME1);
 
			     user=(EditText)findViewById(R.id.use_er);
					String u=user.getText().toString();
					pass=(EditText)findViewById(R.id.Pass);
 
					String p=pass.getText().toString();
			      //Pass value for userName variable of the web service
			        PropertyInfo unameProp =new PropertyInfo();
			        unameProp.setName("userName");//Define the variable name in the web service method
			        unameProp.setValue(u);//set value for userName variable
			        unameProp.setType(String.class);//Define the type of the variable
			        request.addProperty(unameProp);//Pass properties to the variable
 
			      //Pass value for Password variable of the web service
			        PropertyInfo passwordProp =new PropertyInfo();
			        passwordProp.setName("password");
			        passwordProp.setValue(p);
			        passwordProp.setType(String.class);
			        request.addProperty(passwordProp);
 
			        SoapSerializationEnvelope envelope = new SoapSerializationEnvelope(SoapEnvelope.VER11);
			        envelope.setOutputSoapObject(request);
			        HttpTransportSE androidHttpTransport = new HttpTransportSE(URL);
 
			        try{
			            androidHttpTransport.call(SOAP_ACTION1, envelope);
			               SoapPrimitive response = (SoapPrimitive)envelope.getResponse();
			            str=response.toString();
 
 
 
			        }
			        catch(Exception e){
 
			        }
			        runOnUiThread(new Runnable(){
			        	public void run(){
			        		TextView result = (TextView) findViewById(R.id.textView5);
				               result.setText(str);
 
			        	}
			        });
 
			}
 
 
		}).start();
 
 
}
 
 
 
}
si l'utilisateur est un vendeur je veux que son nom sois enregistré dans un Sharedpreferences afin de l'utiliser dans une autre activité la voici :
Activité C:
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
 
package com.example.ecommerce;
 
import android.os.Bundle;
import android.app.Activity;
import android.content.Intent;
import android.view.Menu;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.TextView;
 
public class Accueil_Vendeur extends Activity {
TextView Ajout,Visual,Modif,Supp;
	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.activity_accueil__vendeur);
		Ajout=(TextView)findViewById(R.id.Ajout);
		Visual=(TextView)findViewById(R.id.Visu);
		Modif=(TextView)findViewById(R.id.Modif);
		Supp=(TextView)findViewById(R.id.Supp);
 
 
		Ajout.setOnClickListener(new OnClickListener() {
 
			@Override
						public void onClick(View v) {
				Intent i=new Intent(Accueil_Vendeur.this,Ajout.class);
				startActivity(i);
			}
		});
 
			Visual.setOnClickListener(new OnClickListener() {
 
			@Override
			public void onClick(View v) {
				Intent i=new Intent(Accueil_Vendeur.this,Visual.class);
				startActivity(i);
			}
		});
 
		Modif.setOnClickListener(new OnClickListener() {
 
			@Override
			public void onClick(View v) {
				Intent i=new Intent(Accueil_Vendeur.this,Modif.class);
				startActivity(i);
			}
		});
 
		Supp.setOnClickListener(new OnClickListener() {
 
			@Override
			public void onClick(View v) {
				Intent i=new Intent(Accueil_Vendeur.this,Supp.class);
				startActivity(i);	
			}
		});
	}
 
 
 
}