Service Start 부분

  public int onStartCommand(Intent intent, int flags, int startId) {
     socketClient();
     if(data !=null)
      handleCommand(intent);
        // We want this service to continue running until it is explicitly
        // stopped, so return sticky.
        return START_STICKY;
    }

Service Socket Client 부분

     void socketClient(){
     Socket client;
     try {
   client = new Socket (ipAddress, port);
   //ObjectOutputStream outstream = new ObjectOutputStream(client.getOutputStream());
   ObjectInputStream instream = new ObjectInputStream(client.getInputStream());
   data = (String)instream.readObject();
   client.close();
  } catch (UnknownHostException e) {
   // TODO Auto-generated catch block
   e.printStackTrace();
  } catch (IOException e) {
   // TODO Auto-generated catch block
   e.printStackTrace();
  } catch (ClassNotFoundException e) {
   // TODO Auto-generated catch block
   e.printStackTrace();
  }
    }

안드로이드 메인 액티비티 부분

 public class ExamServiceActivity extends Activity {
 static TextView text1;
    /** Called when the activity is first created. */
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);
        Button bt1 = (Button)findViewById(R.id.button1);
        Button bt2 = (Button)findViewById(R.id.button2);
        
        bt1.setOnClickListener(new View.OnClickListener() {
   
   public void onClick(View arg0) {
    // TODO Auto-generated method stub
    Intent intent = new Intent(ServiceClass.ACTION_FOREGROUND);
    intent.setClass(ExamServiceActivity.this, ServiceClass.class);
    startService(intent);
    text1 = (TextView)findViewById(R.id.textView1);
    text1.setText(ServiceClass.data);
   }
  });
        
        bt2.setOnClickListener(new View.OnClickListener() {
   
   public void onClick(View v) {
    // TODO Auto-generated method stub
    stopService(new Intent(ExamServiceActivity.this, ServiceClass.class));
   }
  });
    }

이렇게 구성되어있습니다.

이상황에서 Service에서 가져온 값을 엑티비티 텍스트 뷰로 표시하고 싶은데 어떻게 하면 좋을까요?

위와 같이 하면 Socket연결은 되는데 가져온 값을 제대로 활용하지 못한거 같아요...

 

 

 공지사항을 다 읽었음