• After 15+ years, we've made a big change: Android Forums is now Early Bird Club. Learn more here.

Apps hello world appname

trepdas

Lurker
I am very new to developing and have a very very noob question hoping someone will be patient and kind enough to help me....
I managed to create a vety basic android app with eclipse which is simply launching browser..
it does open the browser and go to a url i state ....
But when i hit back after the launch i get black screen saying "hello world myappactivity"

can someone tell me how to remove this??
Thanks in advance
 
This is when the phone is booting, trying to launch? What happens when you then press the home button?
 
no it is simply there.
the browser is opened alright but when i hit the back button i get the black screen saying "hello world [appname]activity"

hmm will play around a bit...
 
Can we see your code? It's obvious that the hello world activity is still in the stack after your launch your activity, but it's hard to say what you need to do to remove it without first seeing how you managed to embed your activity into the hello world activity (which you shouldn't have done to begin with)/
 
of course ...

this is the [appname]activity.java which is in :src

package [packagename];

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

public class PackageNameActivity extends Activity {
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
Uri uriUrl = Uri.parse("url for browser to go when launching");
Intent launchBrowser = new Intent(Intent.ACTION_VIEW, uriUrl);
startActivity(launchBrowser);
}
}


here is the androidManifest.xml :

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="[packagename]"
android:versionCode="5"
android:versionName="4.1" >


<uses-sdk android:minSdkVersion="1" android:targetSdkVersion="7" />
<supports-screens android:largeScreens="true" android:normalScreens="true" android:smallScreens="true"/>

<uses-permission android:name="android.permission.INTERNET" />

<application
android:icon="@drawable/ic_launcher"
android:label="@string/app_name" >
<activity android:name=".[AppName]Activity">

<intent-filter>
<action android:name="android.intent.action.MAIN" />

<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>

</manifest>


here is main.xml :

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical" >

<TextView
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="@string/hello"/>

</LinearLayout>


here is strings.xml which is inside the 'values' directory :

<?xml version="1.0" encoding="utf-8"?>
<resources>

<string name="hello">Hello World</string>
<string name="app_name">[appname]</string>

</resources>



I played around with it, remove the string, changed it , removed here and there but didn't make it to go away.
even when no string - it is still giving me the black screen.

I just want it to exit app when hitting the back button....

thank you good people for your help and it's ok to laugh at noobies... :-))




:confused:
 
Oh, you are calling the browser, not a webview.. Well, in that case, the only thing I can think of would be to remove the setContentView line all together. I am not sure, however, if it eill let you do this, but theoretically it should work.

Edit: you could also just change the main.xml layout file to make a splash screen.
 
Hej JonBonazza, thank you very much for your help and attention...

...it does go straight to the url with the browser but the back button was not solved...
it didn't work.
I removed the line and still when you hit the 'back' you get a black screen with the appname at top.

I also removed the <text view> from main.xml to see if anything changes but..nop.

all i want is to launch the browser when app starts (which it works now as it is) and exit when I hit the back button...

any idea ?

thx !!!
 
with the aforementioned line removed, you need to call the finish() method directly after the call to startActivity().
 
Code:
public class PackageNameActivity extends Activity {
     /** Called when the activity is first created. */
     @Override
     public void onCreate(Bundle savedInstanceState) {
          super.onCreate(savedInstanceState);
          Uri uriUrl = Uri.parse("url for browser to go when launching");
          Intent launchBrowser = new Intent(Intent.ACTION_VIEW, uriUrl);
          startActivity(launchBrowser);
          finish();
     }
}
 
Back
Top Bottom