0

I just want to create an app where when the user clicks on the launcher icon, it takes them to my website. I found example code to do this in stackoverflow, and it almost works. The code below does successfully launch a website, bit it also displays a pop up right after saying "The application John Project (process com.john.project) has stopped unexpectedly. Please try again.". I'm guessing I'm not shutting down my app properly? Here's my MainActivity.java:

package com.john.project;

import android.os.Bundle;
import android.app.Activity;
import android.view.Menu;
import android.content.Intent;
import android.net.Uri;

public class MainActivity extends Activity {

    @Override
    protected void onCreate(Bundle savedInstanceState) {

        String url = "http://project.john.com/";
        Intent i = new Intent(Intent.ACTION_VIEW);
        i.setData(Uri.parse(url));
        startActivity(i);

        //super.onCreate(savedInstanceState);
        //setContentView(R.layout.activity_main);

    }

    @Override
    public boolean onCreateOptionsMenu(Menu menu) {
        // Inflate the menu; this adds items to the action bar if it is present.
        getMenuInflater().inflate(R.menu.main, menu);
        return true;
    }

}
John
  • 32,403
  • 80
  • 251
  • 422

2 Answers2

1

You must call super.onCreate() in onCreate(), otherwise you will crash with a SuperNotCalledException.

Karakuri
  • 38,365
  • 12
  • 84
  • 104
  • Also, for the future, it is best to post a full stacktrace from Logcat when you ask about a crash ;) – Karakuri Apr 08 '13 at 03:01
  • Ok thanks that solved the problem. I have a related question. The second time i click on my launcher icon, it opens up a White Screen with the title "JOhn Project". This only happens the second time and onwards. The first time it opens up a web browser with the url I want. Do you know how to prevent this white screen with "John Project" from ever appearing? – John Apr 08 '13 at 03:03
  • This is because it is tying to relaunch your activity, but your activity is already running, so it simply brings it to the foreground. Add `finish();` at the end of onCreate(). This will tell the system to close the activity so that the next time is is launched, it has to be recreated (and will go through onCreate(), open up your webpage, etc) – Karakuri Apr 08 '13 at 03:04
  • Glad it works. Please don't forget to checkmark the answer :) – Karakuri Apr 08 '13 at 03:31
1

Add super.onCreate() at the top of onCreate().

Tuan Vu
  • 6,397
  • 2
  • 14
  • 22