startActivity()由android system_process无限次调用

时间:2013-03-20 10:42:34

标签: android android-intent android-emulator

问题: - startActivity()由android system_process 无限次调用。所以下面的代码打开 MainActivity ,然后MainActivity被冻结/挂起,几分钟后android关闭了自己。

我有两项活动:

  1. RegisterActivity
  2. MainActivity
  3. 注册过程完成后,我想将用户重定向到主屏幕(ieMainActivity),所以我使用此代码开始活动: -

    Button btnSubmit = (Button) findViewById(R.id.btnSubmit);
    btnSubmit.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            // TODO Auto-generated method stub
            Intent intent = new Intent(RegisterActivity.this,MainActivity.class);
            startActivity(intent);  
        }
    });
    

    但是android系统会无限次地调用startActivity()。我通过Logcat找到了这个。 logcat输出是: -

    03-20 10:08:25.756: I/ActivityManager(63): Starting activity: Intent { cmp=com.techdeedapps.fallonmoving/.MainActivity }
    03-20 10:08:25.826: W/InputManagerService(63): Starting input on non-focused client com.android.internal.view.IInputMethodClient$Stub$Proxy@44c7f1b0 (uid=10026 pid=316)
    03-20 10:08:25.826: W/InputManagerService(63): Client not active, ignoring focus gain of: com.android.internal.view.IInputMethodClient$Stub$Proxy@44c4ef28
    03-20 10:08:25.966: I/ActivityManager(63): Starting activity: Intent { cmp=com.techdeedapps.fallonmoving/.MainActivity }
    03-20 10:08:26.036: W/InputManagerService(63): Starting input on non-focused client com.android.internal.view.IInputMethodClient$Stub$Proxy@44c7f1b0 (uid=10026 pid=316)
    03-20 10:08:26.036: W/InputManagerService(63): Client not active, ignoring focus gain of: com.android.internal.view.IInputMethodClient$Stub$Proxy@44c28e48
    03-20 10:08:26.176: I/ActivityManager(63): Starting activity: Intent { cmp=com.techdeedapps.fallonmoving/.MainActivity }
    03-20 10:08:26.246: W/InputManagerService(63): Starting input on non-focused client com.android.internal.view.IInputMethodClient$Stub$Proxy@44c7f1b0 (uid=10026 pid=316)
    03-20 10:08:26.246: W/InputManagerService(63): Client not active, ignoring focus gain of: com.android.internal.view.IInputMethodClient$Stub$Proxy@44c11b98
    03-20 10:08:26.396: I/ActivityManager(63): Starting activity: Intent { cmp=com.techdeedapps.fallonmoving/.MainActivity }
    03-20 10:08:26.437: D/dalvikvm(316): GREF has increased to 201
    03-20 10:08:26.606: I/ActivityManager(63): Starting activity: Intent { cmp=com.techdeedapps.fallonmoving/.MainActivity }
    03-20 10:08:26.676: W/InputManagerService(63): Starting input on non-focused client com.android.internal.view.IInputMethodClient$Stub$Proxy@44c7f1b0 (uid=10026 pid=316)
    03-20 10:08:26.676: W/InputManagerService(63): Client not active, ignoring focus gain of: com.android.internal.view.IInputMethodClient$Stub$Proxy@44de2330
    03-20 10:08:26.816: I/ActivityManager(63): Starting activity: Intent { cmp=com.techdeedapps.fallonmoving/.MainActivity }
    03-20 10:08:26.826: E/SurfaceFlinger(63): createSurface() failed, generateId = -12
    03-20 10:08:26.826: W/WindowManager(63): OutOfResourcesException creating surface
    03-20 10:08:26.826: I/WindowManager(63): Out of memory for surface!  Looking for leaks...
    03-20 10:08:26.826: W/WindowManager(63): No leaked surfaces; killing applicatons!
    03-20 10:08:26.826: W/ActivityManager(63): Killing processes for memory at adjustment 0
    03-20 10:08:26.826: W/ActivityManager(63): Killing for memory: ProcessRecord{44f32af0 316:com.techdeedapps.fallonmoving/10026} (adj 0)
    03-20 10:08:26.826: I/Process(63): Sending signal. PID: 316 SIG: 9
    03-20 10:08:26.836: W/WindowManager(63): Looks like we have reclaimed some memory, clearing surface for retry.
    03-20 10:08:26.836: W/WindowManager(63): Due to memory failure, waiting a bit for next layout
    03-20 10:08:26.856: I/ActivityManager(63): Process com.techdeedapps.fallonmoving (pid 316) has died.
    03-20 10:08:27.176: I/WindowManager(63): WIN DEATH: Window{44fac7d8 com.techdeedapps.fallonmoving/com.techdeedapps.fallonmoving.MainActivity paused=false}
    03-20 10:08:27.196: I/WindowManager(63): WIN DEATH: Window{44faa318 com.techdeedapps.fallonmoving/com.techdeedapps.fallonmoving.MainActivity paused=false}
    

    MainActivity代码:

         public class MainActivity extends Activity {
    AlertDialog.Builder builder;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        // TODO Auto-generated method stub
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);
        builder = new AlertDialog.Builder(this);
    
        Button btnEnter = (Button) findViewById(R.id.btnEnter);
        btnEnter.setOnClickListener(new View.OnClickListener() {
    
            @Override
            public void onClick(View v) {
                // TODO Auto-generated method stub
                if (RegisterActivity.loggedIn) {
                    startActivity(new Intent(MainActivity.this,
                            AddActivity.class));
                } else {
                    Utility.showAlertDialog(builder, "Please Log In!");
                }
            }
    
        Button btnSettings = (Button) findViewById(R.id.btnSettings);
        btnSettings.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                // TODO Auto-generated method stub
                startActivity(new Intent(MainActivity.this,
                        RegisterActivity.class));
            }
        });
    
    }
    

    RegisterActivity代码:

        public class RegisterActivity extends Activity {
         protected void onCreate(Bundle savedInstanceState) {
        // TODO Auto-generated method stub
        super.onCreate(savedInstanceState);
        setContentView(R.layout.register);
        builder = new AlertDialog.Builder(this);
        etName = (TextView) findViewById(R.id.etName);
        etEmail = (TextView) findViewById(R.id.etEmail);
        Button btnSubmit = (Button) findViewById(R.id.btnSubmit);
        btnsubmit.setOnClickListener(new View.OnClickListener() {
    
            @Override
            public void onClick(View v) {
                // TODO Auto-generated method stub
                Intent intent = new Intent(RegisterActivity.this,
                        MainActivity.class);
                startActivity(intent);
    
            }
        });
        }
    }
    

    这个logcat输出是连续的,直到我关闭模拟器!如果我不关闭模拟器,那么android会自动重启。只是系统挂起导致它无限调用startActivity()!

1 个答案:

答案 0 :(得分:0)

其实是我的错.. startActivity()被无限调用,因为当我完成活动时,我又开始了另一项活动!但我感谢所有响应者的帮助。非常感谢你们!...