2012-07-19 3 views
0

내 응용 프로그램과 함께 4.x 장치에 문제가 있습니다. 스플래시 화면에서 실제 응용 프로그램으로 변경하는 동안 스레드가 충돌을 일으키는 것 같습니다.Android : UnsupportedOperationException (스레드 포함)

UnsupportedOperationException screenshot

스플래쉬 활동 코드는 다음과 같습니다 : 여기에 스크린 샷의 주요 활동은 "불행히도 뒤에 (백그라운드에서 작업을 계속 같이

public class Splash extends Activity { 

protected boolean _active = true; 
protected int _splashTime = 3000; // tempo di permanenza spash screen 

/** Called when the activity is first created. */ 
@Override 
public void onCreate(Bundle savedInstanceState) { 
    super.onCreate(savedInstanceState); 
    setContentView(R.layout.splash); 

    Thread splashTread = new Thread() { 
     @Override 
     public void run() { 
      try { 
       int waited = 0; 
       while(_active && (waited < _splashTime)) { 
        sleep(100); 
        if(_active) { 
         waited += 100; 
        } 
       } 
      } catch(InterruptedException e) { 
       // do nothing 
      } finally { 
       finish(); 
       Intent i = new Intent(Splash.this, Test01Activity.class); 
       startActivity(i); 
       stop(); 
      } 
     } 
    }; 
splashTread.start(); 
} 

@Override 
public boolean onTouchEvent(MotionEvent event) { 
    if (event.getAction() == MotionEvent.ACTION_DOWN) { 
     _active = false; 
    } 
    return true; 
} 
} 

는 또한, 응용 프로그램은 정말 충돌 넣은 사람은 아니다, 앱이 작동을 멈췄습니다 "라는 경고가 표시됨). 이 문제는 4.x 장치에서만 발견되었으며 2.x 및 3.x는 모두 작동합니다. 오류는 37 행에 있습니다.

+0

정확히 충돌하는 곳은 어디입니까? LogCat을 붙여주십시오. –

+0

어떤 줄에 충돌이 있습니까 –

+0

코드가이 주제와 동일하게 나타납니다. http://stackoverflow.com/q/4414737/517561 – Sparky

답변

2

예외는 deprecated stop method of Thread class의 사용으로 인한 것 같습니다. ICS 4.0에서 지원되지 않을 수 있습니다.

스레드 대신 Handler을 사용할 수 있습니다.

당신은 onCreate 방법

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

    Handler mHandler = new Handler(); 
     mHandler.postDelayed(new Runnable() { 

      @Override 
      public void run() { 
       Intent i = new Intent(Splash.this, Test01Activity.class); 
       startActivity(i); 
      finish(); 

      } 
     }, _splashTime); 

} 
+0

나는 stop()을 제거 할 수있었습니다. 고맙습니다 – Stefano

0

GUI로 모든 작업이 이벤트 UI 스레드에서 진행되어야합니다 당신의 시작 화면 내부 코드 아래에 시도 할 수 있습니다. Android 4는이 요구 사항에서 더욱 심각합니다. 이는 앱이 그 아래에서 충돌하는 이유 일 수 있습니다. 보시다시피 UI 스레드에서 활동을 변경하지 마십시오. 자세한 내용은 AsyncTask을 참조하십시오.