Log statements not being called in onCreate()
Asked Answered
B

1

7

I have a series of Log statements in my onCreate() method for debugging, but sometimes they just aren't printed in my LogCat. Is there any reasoning for this that anyone is aware of?

Maybe I'm misunderstanding the basics of an Activity's life cycle. I have visited the developer's page, but it still makes no sense.

Let me clarify that the Log calls are displayed if I uninstall the application and then launch it from Eclipse again. However, I am running tests to see the applications functionality once it has already been run.

I have a MainMenu Activity which stems to multiple other activities. When I uninstall the application and re-launch it, it prints what I would expect it to print. Then, I go to my device's settings and Force Quit the application (Is this the right thing to do?). After that, I open my application up again. There is no Log messages from the onCreate() method, but when I move to a different Activity, my MainMenu's onPause() and onStop() methods have Log messages that are printed properly to LogCat.

Any ideas?

EDIT:

I want to add that on a restart, Log messages in the onStart() method are also skipped.

Here is my onCreate/onStart/onPause/onStop methods if you're interested. There is a lot of repeated code within, that was done to try to find out what method was called when the app was restarted. Shouldn't make a difference though, I feel like this is a problem with my method of restarting the application.

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();
}
Bog answered 18/12, 2012 at 18:30 Comment(7)
You might want to show some code.Bobbee
@Bobbee Just added it. Don't think it'll make a difference though, how is it possible to skip an onCreate method all together? I feel like I am terminating the app incorrectly.Bog
Are you sure you're not filtering out that message somehow? Otherwise, I would say it looks like you're doing it correctly.Bobbee
@Bobbee i don't know how that would be possible. They display the first time through, then I choose Force Quit, then reboot, onCreate() and onStart() just do not produce Log messages. Also, the method calls within onCreate and onStart have separate Log messages that are never shown. It must not be calling onCreate or onStart which makes NO sense.Bog
Hmmm. I'm wondering what exactly 'Force Quit' does then. Is it just affecting services? You may need to look for more information on that. On our system, selecting the back button while in an app will destroy the activity. Try that.Bobbee
Well, I don't know whats going on. I just uninstalled the application from my device, cleaned my project, and then ran it again. The first method to appear was onResume...Bog
I'm running into the same issue. I wonder if the LogCat isn't initialized at this point.Tasteful
C
5

I had the same problem with Application.onCreate() logging. I discovered that if I changed the filter from “Show only selected application” to “No Filters” and searched LogCat for the TAG used, then I could see the log messages.

Conchita answered 14/7, 2016 at 8:56 Comment(3)
Since this was so long ago I have no idea what project I asked this question for or how I solved it, so I don't know if I'm supposed to accept your answer. Hopefully someone down the road will find it helpful!Bog
@Bog No worries. :)Conchita
This tip is working well. ThanksCoprology

© 2022 - 2024 — McMap. All rights reserved.