假設我的應用程序已啓動並正在運行。然後我去我的設備主屏幕。導航至設置>>應用程序>>管理應用程序,選擇我的應用程序,然後按Force stop
。'強制停止'在其生命週期中有什麼活動?
哪個Activity
方法會在我下次打開應用程序時調用?在我沒有檢查自己的攻擊之前,我在我的onCreate
,onStart
和onResume
方法中有大量的Log
陳述,但是實際上,當應用程序重新打開時,它們中沒有一個顯示在LogCat
中。
如果您知道Force stop
將我的應用程序置於何種狀態的答案,但缺少的Log
陳述無意義,請分享。我認爲可能有其他問題,除了我錯過Force stop
放置我的程序。
的Android活動週期:
的onCreate()
public void onCreate(Bundle savedInstanceState) {
Log.i(TAG, "Whats going onnnn0");
// This calls all inherited methods, as this is a subclass of Activity.
super.onCreate(savedInstanceState);
if(D) Log.e(TAG, "+++ ON CREATE +++");
Log.i(TAG, "Whats going onnnn");
// Set the view the main.xml
setContentView(R.layout.main);
RelayAPIModel.bluetoothConnected = false;
// Initialize the connection.
setupConnection();
Log.i(TAG, "Whats going onnnn2");
// Check how if bluetooth is enabled on this device.
mService.checkBluetoothState();
// Initialize stuff from PilotMain() method
initMain();
Log.i(TAG, "Whats going onnnn3");
// Add listeners to all of the buttons described in main.xml
buildButtons();
Log.i("HERE", "HERE");
// If the adapter is null, then Bluetooth is not supported
if (mService.getAdapter() == null) {
Toast.makeText(this, R.string.toast_bt_not_avail, Toast.LENGTH_LONG).show();
finish();
return;
}
savedStuff = (SerializableObjects)LocalObjects.readObjectFromFile(getApplicationContext(), "LastDevice.txt");
if(savedStuff != null) {
hasLastDevice = true;
Log.i("HAS", "LAST DEVICE");
Log.i("HAS", savedStuff.getName());
} else {
hasLastDevice = false;
Log.i("HAS NO", "LAST DEVICE");
}
pairedDeviceList = new ArrayList<BluetoothDevice>();
pairedDevices = mService.getAdapter().getBondedDevices();
for(BluetoothDevice device: pairedDevices) {
pairedDeviceList.add(device);
}
if(hasLastDevice) {
for(int i = 0; i < pairedDeviceList.size(); i++) {
Log.i("1 HERE HERE", pairedDeviceList.get(i).getName());
Log.i("1 [email protected]", savedStuff.getName());
if(pairedDeviceList.get(i).getName().equals(savedStuff.getRealName())) {
// THIS IS THE DEVICE WE NEED
previousDevice = pairedDeviceList.get(i);
i = pairedDeviceList.size();
}
}
}
}
在onStart()
public void onStart() {
super.onStart();
if(D) Log.e(TAG, "++ ON START ++");
savedStuff = (SerializableObjects)LocalObjects.readObjectFromFile(getApplicationContext(), "LastDevice.txt");
if(savedStuff != null) {
hasLastDevice = true;
Log.i("HAS", "LAST DEVICE");
Log.i("HAS", savedStuff.getName());
} else {
hasLastDevice = false;
Log.i("HAS NO", "LAST DEVICE");
}
pairedDeviceList = new ArrayList<BluetoothDevice>();
pairedDevices = mService.getAdapter().getBondedDevices();
for(BluetoothDevice device: pairedDevices) {
pairedDeviceList.add(device);
}
if(hasLastDevice) {
for(int i = 0; i < pairedDeviceList.size(); i++) {
Log.i("2 HERE HERE", pairedDeviceList.get(i).getName());
Log.i("2 [email protected]", savedStuff.getName());
if(pairedDeviceList.get(i).getName().equals(savedStuff.getRealName())) {
// THIS IS THE DEVICE WE NEED
previousDevice = pairedDeviceList.get(i);
i = pairedDeviceList.size();
}
}
}
// If BT is not on, request that it be enabled.
// setupChat() will then be called during onActivityResult
if (!mService.getAdapter().isEnabled()) {
Log.i(TAG, "first !isEnabled ");
Intent enableIntent = new Intent(BluetoothAdapter.ACTION_REQUEST_ENABLE);
startActivityForResult(enableIntent, REQUEST_ENABLE_BT);
Log.i(TAG, "second !isEnabled");
// Otherwise, setup the connection
} else {
if (mService == null) {
Log.i(TAG, "setupConnection BEFORE");
setupConnection();
Log.i(TAG, "setupConnection AFTER");
}
}
}
的onResume()
public synchronized void onResume() {
Log.i("RESUME", "HERE");
super.onResume();
if(D) Log.e(TAG, "+ ON RESUME +");
Log.i("RESUME", "AFTER HERE");
// Performing this check in onResume() covers the case in which BT was
// not enabled during onStart(), so we were paused to enable it...
// onResume() will be called when ACTION_REQUEST_ENABLE activity returns.
if (mService != null) {
// Only if the state is STATE_NONE, do we know that we haven't started already
if (mService.getState() == BluetoothService.STATE_NONE) {
// Start the Bluetooth chat services
mService.start();
}
}
}
使用Force Stop後啓動應用程序時,您看到了什麼?它應該從'onCreate()'開始。 – Sam
必須有別的事情正在進行。當我開始使用應用程序時,LogCat中沒有任何內容顯示。我也只是卸載應用程序,清理項目,然後再從eclipse運行它。現在,當我這樣做時,LogCat中沒有任何東西。它真的到處都是,有時它的印刷有時不是。 – JuiCe
最壞的情況是你的手機/ adb連接被搞亂了一點。有時我會啓動一個應用程序,它完全正常工作,adb顯示除* my *應用程序以外的所有日誌輸出。 –