我的Log
方法中有一系列onCreate()
语句用于调试,但有时它们不会打印在我的LogCat
中。有没有人知道的任何理由?
也许我误解了活动生命周期的基础知识。我访问了the developer's page,但它仍然没有意义。
让我澄清一下,如果我卸载应用程序然后再次从Eclipse启动它,则会显示Log
调用。但是,我正在运行测试,以便在应用程序功能运行后查看它。
我有一个MainMenu活动,它源于多个其他活动。当我卸载应用程序并重新启动它时,它会打印出我希望打印的内容。然后,我转到设备的设置和Force Quit
应用程序(这是正确的做法吗?)。之后,我再次打开我的应用程序。 Log
方法中没有onCreate()
条消息,但当我转到其他活动时,我的MainMenu
onPause()
和onStop()
方法有{{} 1}}正确打印到LogCat的消息。
有什么想法吗?
编辑:
我想在重新启动时添加,Log
方法中的Log
消息也会被跳过。
如果您有兴趣,这是我的onCreate / onStart / onPause / onStop方法。内部有很多重复的代码,试图找出重新启动应用程序时调用的方法。但是,不应该有所作为,我觉得这是我的重启应用程序的方法的问题。
onStart()
在onStart()
public void onCreate(Bundle savedInstanceState) {
// 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 HEUH?I@JD", savedStuff.getName() );
if( pairedDeviceList.get( i ).getName().equals( savedStuff.getRealName() ) ) {
// THIS IS THE DEVICE WE NEED
previousDevice = pairedDeviceList.get( i );
i = pairedDeviceList.size();
}
}
}
}
的onPause()
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 HEUH?I@JD", 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" );
}
}
}
的onStop()
@Override
public synchronized void onPause() {
super.onPause();
if(D) Log.e(TAG, "- ON PAUSE -");
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( "4 HERE HERE", pairedDeviceList.get( i ).getName() );
Log.i( "4 HEUH?I@JD", savedStuff.getName() );
if( pairedDeviceList.get( i ).getName().equals( savedStuff.getRealName() ) ) {
// THIS IS THE DEVICE WE NEED
previousDevice = pairedDeviceList.get( i );
i = pairedDeviceList.size();
}
}
}
if( savedStuff != null ) {
Log.i( "HAS", savedStuff.getName() );
}
}
答案 0 :(得分:3)
Application.onCreate()
日志记录遇到了同样的问题。我发现如果我将过滤器从“仅显示选定的应用程序”更改为“无过滤器”并在LogCat中搜索所使用的TAG
,那么我可以看到日志消息。