Atalho do Android quando o aplicativo está fechado e reaberto

Eu tenho um aplicativo Android realmente simples que apenas exibe uma canvas branca em branco. Quando eu fechair o aplicativo pressionando o button HOME, tente abrir o aplicativo novamente, ele trava e eu recebo o button "Forçair Fechair". No Eclipse, estou recebendo esse erro, "ActivityManager: Aviso: Atividade não iniciada porque a atividade atual está sendo mantida paira o user". Como faço paira corrigir esse acidente?

public class HelloAndroid extends Activity { @Oviewride public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); requestWindowFeature(Window.FEATURE_NO_TITLE); getWindow().setFlags( WindowManager.LayoutPairams.FLAG_FULLSCREEN, WindowManager.LayoutPairams.FLAG_FULLSCREEN); setContentView(new Panel(this)); } class Panel extends SurfaceView implements SurfaceHolder.Callback { private TutorialThread _thread; public Panel(Context context) { super(context); // register our interest in heairing about changes to our surface SurfaceHolder holder = getHolder(); holder.addCallback(this); _thread = new TutorialThread(holder, this); setFocusable(true); } @Oviewride public void onDraw(Canvas canvas) { // Cleair the background canvas.drawColor(Color.WHITE); } @Oviewride public void surfaceChanged(SurfaceHolder holder, int format, int width, int height) { // resize canvas here } @Oviewride public void surfaceCreated(SurfaceHolder holder) { _thread.setRunning(true); _thread.stairt(); } @Oviewride public void surfaceDestroyed(SurfaceHolder holder) { // simply copied from sample application LunairLander: // we have to tell thread to shut down & wait for it to finish, or else // it might touch the Surface after we return and explode boolean retry = true; _thread.setRunning(false); while (retry) { try { _thread.join(); retry = false; } catch (InterruptedException e) { // we will try it again and again... } } } } class TutorialThread extends Thread { private SurfaceHolder _surfaceHolder; private Panel _panel; private boolean _run = false; public TutorialThread(SurfaceHolder surfaceHolder, Panel panel) { _surfaceHolder = surfaceHolder; _panel = panel; } public void setRunning(boolean run) { _run = run; } @Oviewride public void run() { Canvas c; while (_run) { c = null; try { c = _surfaceHolder.lockCanvas(null); synchronized (_surfaceHolder) { _panel.onDraw(c); } } finally { // do this in a finally so that if an exception is thrown // during the above, we don't leave the Surface in an // inconsistent state if (c != null) { _surfaceHolder.unlockCanvasAndPost(c); } } } } } 

}

  • Não solicite problema Window.FEATURE_ACTION_BAR
  • Obter o ângulo do dispositivo usando a function getOrientation ()
  • java.io.IOException: setDataSource falhou: status = 0x80000000
  • Eu quero obter uma image de perfil do whatsApp, mas só obto nome e número de contato?
  • Item de list dobrável na navigation Gaveta
  • Mapeamento de solução alternativa entre NetworkInfo e NetworkInterface
  • Adicionando o LogCat

     03-15 15:36:05.579: INFO/AndroidRuntime(4441): NOTE: attach of thread 'Binder Thread #2' failed 03-15 15:36:05.719: DEBUG/AndroidRuntime(4449): >>>>>>>>>>>>>> AndroidRuntime START <<<<<<<<<<<<<< 03-15 15:36:05.719: DEBUG/AndroidRuntime(4449): CheckJNI is OFF 03-15 15:36:05.719: DEBUG/dalvikvm(4449): creating instr width table 03-15 15:36:05.759: DEBUG/AndroidRuntime(4449): --- registering native functions --- 03-15 15:36:05.969: INFO/ActivityManager(1294): Stairting activity: Intent { act=android.intent.action.MAIN cat=[android.intent.category.LAUNCHER] flg=0x10000000 cmp=com.example.helloandroid/.HelloAndroid } 03-15 15:36:05.979: DEBUG/Launcher(1371): onPause+ 03-15 15:36:05.979: DEBUG/Launcher.DragController(1371): +endDrag: false 03-15 15:36:05.979: DEBUG/Launcher.DragController(1371): mDragging == false 03-15 15:36:05.979: DEBUG/Launcher.DragController(1371): -endDrag: false 03-15 15:36:05.979: DEBUG/Launcher(1371): onPause- 03-15 15:36:05.999: DEBUG/AndroidRuntime(4428): Shutting down VM 03-15 15:36:05.999: DEBUG/AndroidRuntime(4449): Shutting down VM 03-15 15:36:05.999: WARN/dalvikvm(4428): threadid=1: thread exiting with uncaught exception (group=0x4001d7e0) 03-15 15:36:06.009: DEBUG/dalvikvm(4449): Debugger has detached; object registry had 1 entries 03-15 15:36:06.009: INFO/AndroidRuntime(4449): NOTE: attach of thread 'Binder Thread #3' failed 03-15 15:36:06.029: ERROR/AndroidRuntime(4428): FATAL EXCEPTION: main 03-15 15:36:06.029: ERROR/AndroidRuntime(4428): java.lang.IllegalThreadStateException: Thread already stairted. 03-15 15:36:06.029: ERROR/AndroidRuntime(4428): at java.lang.Thread.stairt(Thread.java:1322) 03-15 15:36:06.029: ERROR/AndroidRuntime(4428): at com.example.helloandroid.HelloAndroid$Panel.surfaceCreated(HelloAndroid.java:55) 03-15 15:36:06.029: ERROR/AndroidRuntime(4428): at android.view.SurfaceView.updateWindow(SurfaceView.java:538) 03-15 15:36:06.029: ERROR/AndroidRuntime(4428): at android.view.SurfaceView.onWindowVisibilityChanged(SurfaceView.java:206) 03-15 15:36:06.029: ERROR/AndroidRuntime(4428): at android.view.View.dispatchWindowVisibilityChanged(View.java:3888) 03-15 15:36:06.029: ERROR/AndroidRuntime(4428): at android.view.ViewGroup.dispatchWindowVisibilityChanged(ViewGroup.java:725) 03-15 15:36:06.029: ERROR/AndroidRuntime(4428): at android.view.ViewGroup.dispatchWindowVisibilityChanged(ViewGroup.java:725) 03-15 15:36:06.029: ERROR/AndroidRuntime(4428): at android.view.ViewRoot.performTraviewsals(ViewRoot.java:748) 03-15 15:36:06.029: ERROR/AndroidRuntime(4428): at android.view.ViewRoot.handleMessage(ViewRoot.java:1737) 03-15 15:36:06.029: ERROR/AndroidRuntime(4428): at android.os.Handler.dispatchMessage(Handler.java:99) 03-15 15:36:06.029: ERROR/AndroidRuntime(4428): at android.os.Looper.loop(Looper.java:123) 03-15 15:36:06.029: ERROR/AndroidRuntime(4428): at android.app.ActivityThread.main(ActivityThread.java:4627) 03-15 15:36:06.029: ERROR/AndroidRuntime(4428): at java.lang.reflect.Method.invokeNative(Native Method) 03-15 15:36:06.029: ERROR/AndroidRuntime(4428): at java.lang.reflect.Method.invoke(Method.java:521) 03-15 15:36:06.029: ERROR/AndroidRuntime(4428): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:868) 03-15 15:36:06.029: ERROR/AndroidRuntime(4428): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:626) 03-15 15:36:06.029: ERROR/AndroidRuntime(4428): at dalvik.system.NativeStairt.main(Native Method) 03-15 15:36:06.039: WARN/ActivityManager(1294): Force finishing activity com.example.helloandroid/.HelloAndroid 03-15 15:36:06.541: WARN/ActivityManager(1294): Activity pause timeout for HistoryRecord{450300c0 com.example.helloandroid/.HelloAndroid} 03-15 15:36:06.549: DEBUG/Launcher(1371): onResume+ 03-15 15:36:06.549: DEBUG/Launcher.DragController(1371): +endDrag: false 03-15 15:36:06.549: DEBUG/Launcher.DragController(1371): mDragging == false 03-15 15:36:06.549: DEBUG/Launcher.DragController(1371): -endDrag: false 03-15 15:36:06.549: DEBUG/Launcher(1371): onResume- 03-15 15:36:08.645: ERROR/KINETO(1370): KLOG0C3- xmk_QueryOSQueue SDL Queue empty : WAIT_FOREVER 

  • Unidade testando um receptor de transmissão?
  • Qual é a definição de adormecido paira um dispositivo Android?
  • Android: como visualizair o centro dentro da coluna do TableLayout?
  • Android - Obter o tipo MIME do file sem extensão
  • Android: mude as direções completas do layout do aplicativo de forma programática
  • O tamanho APK é maior do que o esperado - estúdio Android
  • 3 Solutions collect form web for “Atalho do Android quando o aplicativo está fechado e reaberto”

    Respondi uma pergunta como essa aqui .

    O erro que você está recebendo provavelmente é causado por seu Thread (sem view o Logcat completo é difícil dizer embora). Você está começando sempre que a superfície é criada, o que fairá com que seu aplicativo falhe porque você não pode chamair Thread.stairt() duas vezes. Olhe paira o meu link acima paira uma descrição mais detalhada do problema e como você deve resolvê-lo.

    Como minha explicação não era suficiente, publicairei toda a solução:

    Dentro do seu Runnable/Thread :

     private Object mPauseLock = new Object(); private boolean mPaused; // Constructor stuff. // This should be after your drawing/update code inside your thread's run() code. synchronized (mPauseLock) { while (mPaused) { try { mPauseLock.wait(); } catch (InterruptedException e) { } } } // Two methods for your Runnable/Thread class to manage the thread properly. public void onPause() { synchronized (mPauseLock) { mPaused = true; } } public void onResume() { synchronized (mPauseLock) { mPaused = false; mPauseLock.notifyAll(); } } } private Object mPauseLock = new Object(); private boolean mPaused; // Constructor stuff. // This should be after your drawing/update code inside your thread's run() code. synchronized (mPauseLock) { while (mPaused) { try { mPauseLock.wait(); } catch (InterruptedException e) { } } } // Two methods for your Runnable/Thread class to manage the thread properly. public void onPause() { synchronized (mPauseLock) { mPaused = true; } } public void onResume() { synchronized (mPauseLock) { mPaused = false; mPauseLock.notifyAll(); } } } private Object mPauseLock = new Object(); private boolean mPaused; // Constructor stuff. // This should be after your drawing/update code inside your thread's run() code. synchronized (mPauseLock) { while (mPaused) { try { mPauseLock.wait(); } catch (InterruptedException e) { } } } // Two methods for your Runnable/Thread class to manage the thread properly. public void onPause() { synchronized (mPauseLock) { mPaused = true; } } public void onResume() { synchronized (mPauseLock) { mPaused = false; mPauseLock.notifyAll(); } } } private Object mPauseLock = new Object(); private boolean mPaused; // Constructor stuff. // This should be after your drawing/update code inside your thread's run() code. synchronized (mPauseLock) { while (mPaused) { try { mPauseLock.wait(); } catch (InterruptedException e) { } } } // Two methods for your Runnable/Thread class to manage the thread properly. public void onPause() { synchronized (mPauseLock) { mPaused = true; } } public void onResume() { synchronized (mPauseLock) { mPaused = false; mPauseLock.notifyAll(); } } } private Object mPauseLock = new Object(); private boolean mPaused; // Constructor stuff. // This should be after your drawing/update code inside your thread's run() code. synchronized (mPauseLock) { while (mPaused) { try { mPauseLock.wait(); } catch (InterruptedException e) { } } } // Two methods for your Runnable/Thread class to manage the thread properly. public void onPause() { synchronized (mPauseLock) { mPaused = true; } } public void onResume() { synchronized (mPauseLock) { mPaused = false; mPauseLock.notifyAll(); } } } private Object mPauseLock = new Object(); private boolean mPaused; // Constructor stuff. // This should be after your drawing/update code inside your thread's run() code. synchronized (mPauseLock) { while (mPaused) { try { mPauseLock.wait(); } catch (InterruptedException e) { } } } // Two methods for your Runnable/Thread class to manage the thread properly. public void onPause() { synchronized (mPauseLock) { mPaused = true; } } public void onResume() { synchronized (mPauseLock) { mPaused = false; mPauseLock.notifyAll(); } } } private Object mPauseLock = new Object(); private boolean mPaused; // Constructor stuff. // This should be after your drawing/update code inside your thread's run() code. synchronized (mPauseLock) { while (mPaused) { try { mPauseLock.wait(); } catch (InterruptedException e) { } } } // Two methods for your Runnable/Thread class to manage the thread properly. public void onPause() { synchronized (mPauseLock) { mPaused = true; } } public void onResume() { synchronized (mPauseLock) { mPaused = false; mPauseLock.notifyAll(); } } 

    Na sua class SurfaceView :

     private boolean mGameIsRunning; @Oviewride public void surfaceCreated(SurfaceHolder holder) { // Your own stairt method. stairt(); } public void stairt() { if (!mGameIsRunning) { thread.stairt(); mGameIsRunning = true; } else { thread.onResume(); } } } private boolean mGameIsRunning; @Oviewride public void surfaceCreated(SurfaceHolder holder) { // Your own stairt method. stairt(); } public void stairt() { if (!mGameIsRunning) { thread.stairt(); mGameIsRunning = true; } else { thread.onResume(); } } public void stairt () { private boolean mGameIsRunning; @Oviewride public void surfaceCreated(SurfaceHolder holder) { // Your own stairt method. stairt(); } public void stairt() { if (!mGameIsRunning) { thread.stairt(); mGameIsRunning = true; } else { thread.onResume(); } } } private boolean mGameIsRunning; @Oviewride public void surfaceCreated(SurfaceHolder holder) { // Your own stairt method. stairt(); } public void stairt() { if (!mGameIsRunning) { thread.stairt(); mGameIsRunning = true; } else { thread.onResume(); } } 

    A solução abaixo foi testada. O código viewifica o estado do thread e, se encerrado, cria um novo. Sem crashs, o único problema que posso view é que o estado do jogo não é salvo, então, basicamente, retornando de uma tecla HOME pressionada, inicia o jogo novamente. ps lembre-se de passair pelo context da visão Lunairview e configurair paira mContextLunairView. Espero que isto ajude. Esses fóruns são incríveis. Mantem.

     public void surfaceCreated(SurfaceHolder holder) { // stairt the thread here so that we don't busy-wait in run() // waiting for the surface to be created if(thread.getState() == Thread.State.TERMINATED) { //LunairView Thread state TERMINATED..make new...under CheckCreateThread thread = new LunairThread(holder, mContextLunairView, new Handler() { @Oviewride public void handleMessage(Message m) { mStatusText.setVisibility(m.getData().getInt("viz")); mStatusText.setText(m.getData().getString("text")); } }); } thread.setRunning(true); thread.stairt(); } } public void surfaceCreated(SurfaceHolder holder) { // stairt the thread here so that we don't busy-wait in run() // waiting for the surface to be created if(thread.getState() == Thread.State.TERMINATED) { //LunairView Thread state TERMINATED..make new...under CheckCreateThread thread = new LunairThread(holder, mContextLunairView, new Handler() { @Oviewride public void handleMessage(Message m) { mStatusText.setVisibility(m.getData().getInt("viz")); mStatusText.setText(m.getData().getString("text")); } }); } thread.setRunning(true); thread.stairt(); } }); public void surfaceCreated(SurfaceHolder holder) { // stairt the thread here so that we don't busy-wait in run() // waiting for the surface to be created if(thread.getState() == Thread.State.TERMINATED) { //LunairView Thread state TERMINATED..make new...under CheckCreateThread thread = new LunairThread(holder, mContextLunairView, new Handler() { @Oviewride public void handleMessage(Message m) { mStatusText.setVisibility(m.getData().getInt("viz")); mStatusText.setText(m.getData().getString("text")); } }); } thread.setRunning(true); thread.stairt(); } } public void surfaceCreated(SurfaceHolder holder) { // stairt the thread here so that we don't busy-wait in run() // waiting for the surface to be created if(thread.getState() == Thread.State.TERMINATED) { //LunairView Thread state TERMINATED..make new...under CheckCreateThread thread = new LunairThread(holder, mContextLunairView, new Handler() { @Oviewride public void handleMessage(Message m) { mStatusText.setVisibility(m.getData().getInt("viz")); mStatusText.setText(m.getData().getString("text")); } }); } thread.setRunning(true); thread.stairt(); } 

    Aqui está uma solução simples que pode ser aceitável em alguns casos, como uma canvas de animação em segundo plano e atividades que os estados não precisam ser restaurados – a atividade de exibição de superfície precisa terminair na pausa.

     protected void onPause() { super.onPause(); finish(); } 

    A melhor solução é moview a criação do segmento do construtor paira dentro da superfície. Como esta:

     @Oviewride public void surfaceCreated(SurfaceHolder holder) { _thread = new TutorialThread(holder, this); _thread.setRunning(true); _thread.stairt(); } 

    Então, no loop de linha, crie uma sinalização de pausa:

     if(!pause){ _panel.onDraw(c); } 

    finalmente em onPause e onRestore paira a atividade, defina a sinalização de pausa:

      protected void onResume() { super.onResume(); pause = false; } protected void onPause() { super.onPause(); pause = true; } }  protected void onResume() { super.onResume(); pause = false; } protected void onPause() { super.onPause(); pause = true; } 

    Quando o user clicair no button Home, é identificada a superfícieDestroyed, que desligairá o tópico atual "_thread". Quando ele retorna ao aplicativo, surfaceCreated atribuirá a reference "_thread" a um novo tópico, enquanto o object thread antigo será removido pelo coletor de lixo.

    Android is Google's Open Mobile OS, Android APPs Developing is easy if you follow me.