[android-developers] After an exception appears this exception keeps coming back until the program has been reset.

2010-09-16 Thread Saren Inden
Hellow,

I am making a program that is capable of sending and receiving as a
server or a client. The program works but once I have an exception
(timeout because the client/server isn't initialized).

Example:
pc as server ==> on
android as client ==> connect, no problem
disable client and server
connect android client ==> timeout on socket
server ==> on
connect android client ==> same timeout message directly (without the
4500 ms delay)

I tried a lot of things but without the time out the program keeps
hanging and android asks if I want to close it or without the proper
catch exception it crashes (of course).

The code:

package muco.NetwerkServerClient;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.net.ServerSocket;
import java.net.Socket;
import java.net.SocketTimeoutException;
import java.net.UnknownHostException;

import android.app.Activity;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.TextView;

public class netwerkServerClient extends Activity {
  /** Called when the activity is first created. */
  /** Layout values*/
  EditText edit1;
  TextView text2;
  Button knop1, knop2, knop3, knop4, knop5, knop6, knop7, knop8;

  /** Save instance values*/

  /** Client values */
  Socket clientSocket = null;
  BufferedReader inClient = null;
  PrintWriter outClient = null;
  boolean clientInitialised = false;

  /** Server values */
  Socket serverSocket = null;
  ServerSocket server = null;
  BufferedReader inServer = null;
  PrintWriter outServer = null;
  boolean serverInitialised = false;

  /** Common network values */
  int port;
  int maxPort = 65535;
  String ip = null;
  int timeOut = 4500;

  boolean ipSet = false;
  boolean portSet = false;

  /** Values */


  @Override
  public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.relative);

edit1 = (EditText) findViewById(R.id.edit_1);

knop1 = (Button) findViewById(R.id.knop_1);
knop1.setOnClickListener(new View.OnClickListener() {
  public void onClick(View v) {
knop1(v);
  }//public void onClick(View v)
});//knop1.setOnClickListener(new View.OnClickListener()

knop2 = (Button) findViewById(R.id.knop_2);
knop2.setOnClickListener(new View.OnClickListener() {
  public void onClick(View v) {
knop2(v);
  }//public void onClick(View v)
});//knop2.setOnClickListener(new View.OnClickListener()

knop3 = (Button) findViewById(R.id.knop_3);
knop3.setOnClickListener(new View.OnClickListener() {
  public void onClick(View v) {
knop3(v);
  }//public void onClick(View v)
});//knop3.setOnClickListener(new View.OnClickListener()

knop4 = (Button) findViewById(R.id.knop_4);
knop4.setOnClickListener(new View.OnClickListener() {
  public void onClick(View v) {
knop4(v);
  }//public void onClick(View v)
});//knop4.setOnClickListener(new View.OnClickListener()

knop5 = (Button) findViewById(R.id.knop_5);
knop5.setOnClickListener(new View.OnClickListener() {
  public void onClick(View v) {
knop5(v);
  }//public void onClick(View v)
});//knop5.setOnClickListener(new View.OnClickListener()

knop6 = (Button) findViewById(R.id.knop_6);
knop6.setOnClickListener(new View.OnClickListener() {
  public void onClick(View v) {
knop6(v);
  }//public void onClick(View v)
});//knop6.setOnClickListener(new View.OnClickListener()

knop7 = (Button) findViewById(R.id.knop_7);
knop7.setOnClickListener(new View.OnClickListener() {
  public void onClick(View v) {
knop7(v);
  }//public void onClick(View v)
});//knop7.setOnClickListener(new View.OnClickListener()

knop8 = (Button) findViewById(R.id.knop_8);
knop8.setOnClickListener(new View.OnClickListener() {
  public void onClick(View v) {
knop8(v);
  }//public void onClick(View v)
});//knop8.setOnClickListener(new View.OnClickListener()

text2 = (TextView) findViewById(R.id.text_2);
  }//  public void onCreate(Bundle savedInstanceState) {

  @Override
  public void onPause() {
super.onPause();
  }//public void onPause()

  @Override
  public void onSaveInstanceState(Bundle outState) {
super.onSaveInstanceState(outState);
  }//public void onSaveInstanceState(Bundle outState

  @Override
  public void onRestoreInstanceState(Bundle outState) {
super.onRestoreInstanceState(outState);
  }//public void onRestoreInstanceState(Bundle outState)

  @Override
  public void onDestroy() {
  super.onDestroy();
  }//public void onDestroy()

  void knop1(View v) {//inschakelen als server
text

[android-developers] Thread crash if activity is restarted

2010-10-01 Thread Saren Inden
Good day,

I am writing a program that uses a UDP poort to listen to information
send from a system. First the users sees an activity that allows them
to close the activity or start it on a port they can select (edittext)

The port is checked and if correct a new activity is launched. This
display a view items with the received information and a return
button. When started the it also launches a thread for the UDP
connection. In this thread there is a while loop that runs on a
boolean value in the activity.

The problems occurs when the user returns from the information screen
to the login and logs in again.
When they exit the information screens the following commands are
called:

active = false; //a while loop in the the thread
ServerThread.serverInitialised = false; //a while loop in the thread
InlogScherm.restart = false; //a value indicating if the users exits
the program or it only lost focus
finish(); // closes the current activity?

When logged in again the activity crashes directly. After that you can
log in, exit login, crash, login, exit, etc
by adding the command thread.close the activity closes with an error
screen (deprecated command). But a new login doesn't gives any errors
so my guess is that the error is in the fact that the thread isn't
closed.

I can't find any way to close or destroy the thread and let it stop by
stopping the while loop doesn't solves the crashes.

Does anyone have an idea on how to solve this problem?
(The code for the thread is in a different file)

-- 
You received this message because you are subscribed to the Google
Groups "Android Developers" group.
To post to this group, send email to android-developers@googlegroups.com
To unsubscribe from this group, send email to
android-developers+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en