2015-08-29 153 views
0

我每次嘗試與應用程序進行交互時都會遇到此錯誤。我不知道我應該寫入onResume方法。執行停止未恢復的活動:

package hu.frontrider.space; 

import android.content.Intent; 
import android.support.v7.app.ActionBarActivity; 
import android.os.Bundle; 
import android.view.Menu; 
import android.view.MenuItem; 
import android.view.View; 
import android.view.Window; 
import android.view.WindowManager; 
import android.widget.Button; 

import hu.frontrider.space.Helper.OrientationUtils; 


public class MainMenu extends ActionBarActivity { 

    private static Button start_button; 
    private static Button exit_button; 


    @Override 
    protected void onCreate(Bundle savedInstanceState) { 
     super.onCreate(savedInstanceState); 

     getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN, 
       WindowManager.LayoutParams.FLAG_FULLSCREEN); 


     setContentView(R.layout.activity_main_menu); 
     StartButtonClick(); 
     OrientationUtils.lockOrientationPortrait(MainMenu.this); 

    } 
    public void StartButtonClick() 
    { 
     start_button = (Button)findViewById(R.id.StartButton); 

     start_button.setOnClickListener(
       new View.OnClickListener() { 
        @Override 
        public void onClick(View v) { 

         Intent game = new Intent("hu.frontrider.space.GameActivity"); 
         startActivity(game); 

        } 

       } 

     ); 


    } 

    public void ExitButonClick() 
    { 

     exit_button.setOnClickListener(
       new View.OnClickListener() { 
        @Override 
        public void onClick(View v) { 

         System.runFinalizersOnExit(true); 
         System.exit(0); 
        } 

       } 
     ); 
    } 



} 

錯誤日誌。看起來,如果我嘗試進行任何交互,線程會觸發幾次,然後整個事情就會凍結,如果我沒有觸碰任何事情,則什麼都不會發生。我有一段時間沒有觸及這項活動。

08-29 12:46:45.345 11566-11566/hu.frontrider.space E/ActivityThread﹕ Performing stop of activity that is not resumed: {hu.frontrider.space/hu.frontrider.space.MainMenu} 
    java.lang.RuntimeException: Performing stop of activity that is not resumed: {hu.frontrider.space/hu.frontrider.space.MainMenu} 
      at android.app.ActivityThread.performStopActivityInner(ActivityThread.java:3492) 
      at android.app.ActivityThread.handleStopActivity(ActivityThread.java:3579) 
      at android.app.ActivityThread.access$1200(ActivityThread.java:179) 
      at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1351) 
      at android.os.Handler.dispatchMessage(Handler.java:102) 
      at android.os.Looper.loop(Looper.java:146) 
      at android.app.ActivityThread.main(ActivityThread.java:5641) 
      at java.lang.reflect.Method.invokeNative(Native Method) 
      at java.lang.reflect.Method.invoke(Method.java:515) 
      at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1288) 
      at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1104) 
      at dalvik.system.NativeStart.main(Native Method) 
08-29 12:46:46.575 11566-11566/hu.frontrider.space I/ProjectileHandler﹕ Added: [email protected] 
08-29 12:46:46.645 11566-11566/hu.frontrider.space I/ProjectileHandler﹕ Added: [email protected] 
08-29 12:46:46.725 11566-11566/hu.frontrider.space I/ProjectileHandler﹕ Added: [email protected] 
08-29 12:54:42.545 12655-12655/hu.frontrider.space I/dalvikvm﹕ Could not find method android.content.res.TypedArray.getChangingConfigurations, referenced from method android.support.v7.internal.widget.TintTypedArray.getChangingConfigurations 
08-29 12:54:42.545 12655-12655/hu.frontrider.space W/dalvikvm﹕ VFY: unable to resolve virtual method 410: Landroid/content/res/TypedArray;.getChangingConfigurations()I 
08-29 12:54:42.545 12655-12655/hu.frontrider.space D/dalvikvm﹕ VFY: replacing opcode 0x6e at 0x0002 
08-29 12:54:42.545 12655-12655/hu.frontrider.space I/dalvikvm﹕ Could not find method android.content.res.TypedArray.getType, referenced from method android.support.v7.internal.widget.TintTypedArray.getType 
08-29 12:54:42.545 12655-12655/hu.frontrider.space W/dalvikvm﹕ VFY: unable to resolve virtual method 432: Landroid/content/res/TypedArray;.getType (I)I 
08-29 12:54:42.545 12655-12655/hu.frontrider.space D/dalvikvm﹕ VFY: replacing opcode 0x6e at 0x0002 
08-29 12:54:42.755 12655-12655/hu.frontrider.space D/OpenGLRenderer﹕ Enabling debug mode 0 
08-29 12:54:44.285 12655-12655/hu.frontrider.space I/gameactivity﹕ thread started 
08-29 12:54:44.295 12655-12655/hu.frontrider.space I/drawingstart﹕ screensize: Point(320, 480) 
08-29 12:54:45.355 12655-12655/hu.frontrider.space I/ProjectileHandler﹕ Added: [email protected] 
08-29 12:54:45.405 12655-12655/hu.frontrider.space I/ProjectileHandler﹕ Added: [email protected] 
08-29 12:54:45.475 12655-12655/hu.frontrider.space I/ProjectileHandler﹕ Added: [email protected] 
08-29 12:54:45.545 12655-12655/hu.frontrider.space I/ProjectileHandler﹕ Added: [email protected] 
08-29 12:55:06.505 12655-12658/hu.frontrider.space I/dalvikvm﹕ threadid=3: reacting to signal 3 
08-29 12:55:06.565 12655-12658/hu.frontrider.space I/dalvikvm﹕ Wrote stack traces to '/data/anr/traces.txt' 
08-29 12:58:02.335 12774-12774/hu.frontrider.space I/gameactivity﹕ thread started 
08-29 12:58:02.335 12774-12774/hu.frontrider.space I/drawingstart﹕ screensize: Point(320, 480) 
08-29 12:58:15.195 12774-12774/hu.frontrider.space I/ProjectileHandler﹕ Added: [email protected] 
08-29 12:58:15.245 12774-12774/hu.frontrider.space I/ProjectileHandler﹕ Added: [email protected] 
08-29 12:58:15.305 12774-12774/hu.frontrider.space I/ProjectileHandler﹕ Added: [email protected] 
08-29 12:58:15.375 12774-12774/hu.frontrider.space I/ProjectileHandler﹕ Added: [email protected] 
08-29 12:58:15.445 12774-12774/hu.frontrider.space I/ProjectileHandler﹕ Added: [email protected] 

回答

0

你不應該通過調用退出應用程序:

System.exit(0); 

你最好打電話

finish(); 

public void ExitButonClick() 
{ 

    exit_button.setOnClickListener(
      new View.OnClickListener() { 
       @Override 
       public void onClick(View v) { 

        finish(); 
       } 

      } 
    ); 
} 

的onClickListener內。 finish()尊重活動的生命週期,而exit()不尊重活動的生命週期。

相關問題