일전에 자바로 성적확인어플을 짰는데 이걸 안드로이드로 어떻게 옮기냐고 질문했던 사람입니다.

 

인터넷 검색해서 어떻게 짜집기좀 해서 완성은 시켰는데 진저브레드 에뮬레이터에 잘 돌아간다고 생각했다가 폰으로 테스트해보니 ics에서 스트릭트모드라는거에 걸려서 강제종료되네요-_-;;

 

어플은 로그인과정은 메인에서, 성적확인은 서비스로 작동하도록 구현했습니다.

 

일단 메시지를보니 네트워크때문에 걸려서 강제종료가 되는데 이럴경우에는 다른 보이지 않는 액티비티를 만들어서 해결하면 되는건지 아니면 다른 어떤 간편한 방법이 있는지 궁금합니다. 또 서비스로 작동되는 부분도 네트워크 연결이 들어가는데 이 부분은 문제가 없는지 궁금합니다(아래는 로그인부분 소스)

 

 public class ScoreActivity extends Activity {
 public static EditText id;
 private EditText passwd;
 public static TextView scoreOpen;
 private ProgressDialog pDialog;
 private LinearLayout layout01;
 private Button button;
 private Button button1;
 public static HttpClient http;
 public Intent intent;
 public boolean loginCheck=false;
 public boolean serviceCheck=false;
 /** Called when the activity is first created. */
 @Override
 public void onCreate(Bundle savedInstanceState) {
  super.onCreate(savedInstanceState);
  setContentView(R.layout.main);
  id = (EditText) findViewById(R.id.id);
  passwd = (EditText) findViewById(R.id.passwd);
  button = (Button) findViewById(R.id.loginButton);
  button1 = (Button) findViewById(R.id.processButton);
  scoreOpen = (TextView) findViewById(R.id.scoreOpen);
  layout01 = (LinearLayout) findViewById(R.id.layout01);
  intent = new Intent(this, BGCheck.class);
  button.setOnClickListener(new View.OnClickListener() {
   
   @Override
   public void onClick(View v) {
    // TODO Auto-generated method stub
    loginProcess();
   }
  });
  button1.setOnClickListener(new View.OnClickListener() {
   
   @Override
   public void onClick(View v) {
    // TODO Auto-generated method stub
    if (loginCheck){
     if (!serviceCheck) {
      startService(intent);
      serviceCheck=true;
      Toast.makeText(ScoreActivity.this, "성적확인 실행",Toast.LENGTH_LONG).show();
     }else{
      stopService(intent);
      serviceCheck=false;
      Toast.makeText(ScoreActivity.this, "성적확인 중지",Toast.LENGTH_LONG).show();
     } 
    }else{
     Toast.makeText(ScoreActivity.this, "로그인이 되어있지 않습니다",Toast.LENGTH_LONG).show();
    }
    
   }
  });
 }
 private final Handler handler = new Handler() {
  @Override
  public void handleMessage(Message msg) {
   pDialog.dismiss();
   String result = msg.getData().getString("RESULT");
   if (result.equals("success")) {
    Toast.makeText(ScoreActivity.this, "로그인 성공",Toast.LENGTH_LONG).show();
   } else {
    Toast.makeText(ScoreActivity.this, "로그인 실패", Toast.LENGTH_LONG) .show();
   }
  }
 };
 public String parsingData(InputStream input){
        String result=null;
        try {
         StringBuffer sb=null;
         BufferedReader br = new BufferedReader(new InputStreamReader(input, "EUC-KR"));
   sb = new StringBuffer();
   String strData = "";
   while ((strData = br.readLine()) != null) {
   sb.append(strData);
   String pattern="접속중";
   Pattern p=Pattern.compile(pattern);
   Matcher m=p.matcher(sb.toString());
   int i=0;
   while (m.find()) {
    i++;
   }
   if (i>=1) {
    result="success";
    loginCheck=true;
   }else{
    result="failed";
    loginCheck=false;
   }
         }
         }catch(Exception e){e.printStackTrace();}
         return result;
     }
 public void loginProcess() {
  final ResponseHandler<String> responseHandler = new ResponseHandler<String>() {
   @Override
   public String handleResponse(HttpResponse response)
     throws ClientProtocolException, IOException {
    String result = null;
    HttpEntity entity = response.getEntity();
    result = parsingData(entity.getContent());
    Message message = handler.obtainMessage();
    Bundle bundle = new Bundle();
    if (result.equals("success"))
     bundle.putString("RESULT", "success");
    else
     bundle.putString("RESULT", "failed");
    message.setData(bundle);
    handler.sendMessage(message);
    return result;
   }
  };
  pDialog = ProgressDialog.show(this, "", "로그인 처리중....");
  new Thread() {
   @Override
   public void run() {
    String url = "http://myiweb.mju.ac.kr/servlet/sys.sys01.Sys01Svl01";
    http = new DefaultHttpClient();
    try {
     ArrayList<NameValuePair> nameValuePairs = new ArrayList<NameValuePair>();
     nameValuePairs.add(new BasicNameValuePair("user_id", id.getText().toString()));
     nameValuePairs.add(new BasicNameValuePair("passwd", passwd.getText().toString()));
     nameValuePairs.add(new BasicNameValuePair("attribute","login"));
     HttpPost httpPost = new HttpPost(url);
     UrlEncodedFormEntity entityRequest = new UrlEncodedFormEntity(nameValuePairs, "UTF-8");
     httpPost.setEntity(entityRequest);
     http.execute(httpPost, responseHandler);
    } catch (Exception e) {
     e.printStackTrace();
    }
   }
  }.start();
 }
}