0
問題: - startActivity()被android 調用system_process無限次。所以下面的代碼打開MainActivity但隨後MainActivity被凍結/掛起,幾分鐘後android關閉。startActivity()被android系統進程無限次調用
我有兩個活動:
- RegisterActivity
- MainActivity
registeration過程完成後,我想將用戶重定向到主屏幕(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);
}
});
但是startActivit y()被android系統稱爲無限次。我通過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 [email protected] (uid=10026 pid=316)
03-20 10:08:25.826: W/InputManagerService(63): Client not active, ignoring focus gain of: [email protected]
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 [email protected] (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$St[email protected]
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 [email protected] (uid=10026 pid=316)
03-20 10:08:26.246: W/InputManagerService(63): Client not active, ignoring focus gain of: [email protected]
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 [email protected] (uid=10026 pid=316)
03-20 10:08:26.676: W/InputManagerService(63): Client not active, ignoring focus gain of: [email protected]
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()!
發佈更多代碼。我猜你在調用performClick循環或其他東西。或者它在您的HomeActivity – njzk2 2013-03-20 10:44:20
嘗試刪除結束() – Kunal 2013-03-20 10:44:26
請發佈註冊活動的完整代碼 – 2013-03-20 10:46:03