デバッグ用のメソッドに一連のLog
ステートメントがありますが、 . 誰もが知っている理由はありますか?onCreate()
LogCat
アクティビティのライフサイクルの基本を誤解しているのかもしれません。開発者のページにアクセスしましたが、それでも意味がありません。
Log
アプリケーションをアンインストールしてから Eclipse から再度起動すると、呼び出しが表示されることを明確にします。ただし、既に実行されているアプリケーションの機能を確認するためのテストを実行しています。
他の複数のアクティビティに由来する MainMenu アクティビティがあります。アプリケーションをアンインストールして再起動すると、期待どおりに印刷されます。次に、デバイスの設定とForce Quit
アプリケーションに移動します (これは正しいことですか?)。その後、アプリケーションを再度開きます。Log
メソッドからのメッセージはありませんonCreate()
が、別のアクティビティに移動すると、とメソッドMainMenu
のメッセージが LogCat に正しく出力されます。onPause()
onStop()
Log
何か案は?
編集:
再起動時に追加したいのですがLog
、メソッド内のメッセージonStart()
もスキップされます。
興味があれば、これが私の onCreate/onStart/onPause/onStop メソッドです。アプリが再起動されたときにどのメソッドが呼び出されたかを調べるために行われた、多くの繰り返しコードがあります。違いはありませんが、これはアプリケーションを再起動する方法に問題があるように感じます。
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();
}
}
}
}
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 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" );
}
}
}
onPause()
@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() );
}
}
onStop()
public void onStop() {
super.onStop();
if(D) Log.e(TAG, "-- ON STOP --");
if( savedStuff != null ) {
Log.i( "HAS", savedStuff.getName() );
}
// Relay();
}