Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

onCreate() isn't being called

I just got a very strange problem which I have now spendt hours trying to solve. When I try to run my android app (both on my phone and in the emulator) I get nothing. The activity label from the AndroidManifest file (android:label="@string/list_name") is set correctly, but otherwise I just have a blink screen.

I inserted a breakpoint together with 30 Log.d()'s right after the super() in my onCreate() method, but the breakpoint is never reached, and the Log.d()'s are never printed. Also, I do not get any exceptions in logcat.

The app worked before, and I have no idea how the it can be that the breakpoint never is reached.

PS: It is my main activity

PS2: I've cleaned the project, rebuilt it, rebooted. The problem didn't disappear :(

PS3: My onCreate() is quite long, but this is how it starts:

@Override
public void onCreate(Bundle savedInstanceState)
    {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.episode);
        Log.d("Very Strange", "This is never printed");
        Log.d("Very Strange", "This is never printed");
        // no breakpoints is every reached

My manifest file can be found here: http://pastebin.com/UcKbYeGC

like image 664
Martin Hansen Avatar asked Jan 28 '26 22:01

Martin Hansen


2 Answers

Try this:

 public void onCreate(Bundle savedInstanceState)
 {
    Log.d("Very Strange", "Printed #1?");
    super.onCreate(savedInstanceState);
    Log.d("Very Strange", "Printed #2?");
    setContentView(R.layout.episode);
    Log.d("Very Strange", "This is never printed");
    Log.d("Very Strange", "This is never printed");

Just an offtopic tip: use a control version system to ensure you can rollback or compare the working one with the current

like image 156
FerranB Avatar answered Jan 30 '26 12:01

FerranB


The call of super() is not correct, as it just calls the empty constructor of the Activity class. You need to call the static method super.onCreate() in order to generate the Activity correctly.

like image 43
keyboardsurfer Avatar answered Jan 30 '26 13:01

keyboardsurfer



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!