übergeben werden Ich bin ein Neuling für Android. Ich möchte eine Anwendung erstellen, die den Standort Benutzer1 mithilfe von ServerSocket an den Benutzer2 sendet.Wie Daten von einer Aktivität zu einer anderen Aktivität in Android
public class ToMain extends Activity {
TextView info, infoip, msg;
String message ="";
ServerSocket serverSocket;
String s="",t="";
public Double b,c;
public int i;
private class SocketServerThread extends Thread {
static final int SocketServerPORT = 8080;
int count = 0;
@Override
public void run() {
Socket socket = null;
DataInputStream dataInputStream = null;
DataOutputStream dataOutputStream = null;
try {
serverSocket = new ServerSocket(SocketServerPORT);
ToMain.this.runOnUiThread(new Runnable() {
@Override
public void run() {
info.setText("I'm waiting here: "
+ serverSocket.getLocalPort());
}
});
while (true) {
socket = serverSocket.accept();
dataInputStream = new DataInputStream(
socket.getInputStream());
dataOutputStream = new DataOutputStream(
socket.getOutputStream());
String messageFromClient = "";
//If no message sent from client, this code will block the program
messageFromClient = dataInputStream.readUTF();
ich spaltete sich die Breite und Länge auf diese Weise in der Server-Seite
for(int j=0;j<i;j++){
if(messageFromClient.charAt(j)!='+' && bool==false){
s=s+messageFromClient.charAt(j);
}
else{
bool=true;
}
if(bool){
t=t+messageFromClient.charAt(j);
}
}
ich in diesen Lagern zwei Variable
b = Double.parseDouble(s);
c = Double.parseDouble(t);
ToMain.this.runOnUiThread(new Runnable() {
@Override
public void run() {
}
});
String msgReply = "Location Sent!" + count;
dataOutputStream.writeUTF(msgReply);
Ich möchte von hier aus auf die Haupt jene Variable senden Aktivität, die die Karte enthalten
// startActivity(intent);
}
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
final String errMsg = e.toString();
ToMain.this.runOnUiThread(new Runnable() {
@Override
public void run() {
}
});
} finally {
if (socket != null) {
try {
socket.close();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
if (dataInputStream != null) {
try {
dataInputStream.close();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
if (dataOutputStream != null) {
try {
dataOutputStream.close();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
}
}
}
Wie gebe ich a und b an die Hauptaktivität weiter.
Mögliche Duplikat http://stackoverflow.com/questions/18146614/how-to-send-string-from-one-activity-to-another –
Verwendung sharedPrefrences – Abhishek
Thank u. Es gibt mir eine Fehlermeldung mesg: Nicht statische Methode 'putExtras() kann nicht Referenz aus dem statischen Kontext sein. Hilfe @ Alok Gupta –