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

Apps Vogella Tutorial

BranMan

Lurker
Jun 22, 2011
4
0
I'm a C++ and C# programmer and I've been practicing to make android applications to expand my knowledge. Upon downloading eclipse and the android SDK I started off with vogella's basic tutorial for a temperature converter.

After doing that tutorial I continued onto a menu tutorial where I came upon problems. Here is a link to the tutorial:Android Development Tutorial - Gingerbread

I'm on #7 and upon creating the preferences.xml file and adding the two attributes it told me to insert code. It doesn't specify where to put this code and I assumed it would be in the HelloPreferences.java file since there are no other available files to add activities to. Then it says to modify the manifest file to make it an actual activity. I did that step but the program still tells me that the Preferences activity needs to be defined in its own file.

I looked online for solutions to adding a new activity and everyone says either to make a .java file or to add a period in-front of the activity name inside of the manifest file. I tried the period solution and that doesn't solve anything. Is there something in the tutorial that's obvious and I've missed it? I'm so lost and I really want to learn how to make android platform programs. I would greatly appreciate any help.
 
I apologize for the long response. The package name is de.vogella.android.preferences.

Here is the xml for the manifest file:

Code:
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
      package="de.vogella.android.preferences"
      android:versionCode="1"
      android:versionName="1.0">
    <uses-sdk android:minSdkVersion="8" />

    <application android:icon="@drawable/icon" android:label="@string/app_name">
        <activity android:name=".HelloPreferences"
                  android:label="@string/app_name">
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />
                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>
        </activity>
        <activity android:label="Preferences" android:name="Preferences"></activity>

    </application>
</manifest>
 
Upvote 0
I've done what you have suggested and I'm still getting told that Preferences needs to be defined in its own file. I've seen other people talking about having multiple Activities in a single file but I can't find a clear way to do it. Here is what I have in my HelloPreferences.java file. Maybe I'm missing something.

Code:
package de.vogella.android.preferences;

import android.app.Activity;
import android.os.Bundle;
import android.view.Menu;
import android.view.MenuInflater;
import android.view.MenuItem;
import android.widget.Toast;
import android.preference.PreferenceActivity;

//import android.preference.PreferenceActivity;

public class HelloPreferences extends Activity 
{
    /** Called when the activity is first created. */
    @Override
    public void onCreate(Bundle savedInstanceState) 
    {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);
    }
    
    @Override
    public boolean onCreateOptionsMenu(Menu menu)
    {
    	MenuInflater inflater = getMenuInflater();
    	inflater.inflate(R.menu.menu, menu);
    	return true;
    }
    
    @Override
    public boolean onOptionsItemSelected(MenuItem item)
    {
    	Toast.makeText(this, "Just a test", Toast.LENGTH_SHORT).show();
    	return true;
    	
    }
}

public class Preferences extends PreferenceActivity
{
	/** Called when the activity is first created.*/
	@Override
	public void onCreate(Bundle savedInstanceState)
	{
		super.onCreate(savedInstanceState);
		addPreferencesFromResource(R.xml.preferences);
	}
}

Adding the period in front of Preferences and moving the sdk version tag didn't seem to do anything but here is what my manifest file is now.

Code:
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
      package="de.vogella.android.preferences"
      android:versionCode="1"
      android:versionName="1.0">
    

    <application android:icon="@drawable/icon" android:label="@string/app_name">
        <activity android:name=".HelloPreferences"
                  android:label="@string/app_name">
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />
                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>
        </activity>
        <activity android:label="Preferences" android:name=".Preferences"></activity>

    </application>
    <uses-sdk android:minSdkVersion="8" />
</manifest>

I really do appreciate this help. If you think this tutorial is too complicated for someone new to eclipse or if it's doing something wrong, maybe I should just forget it, but I still want to learn how to handle multiple activities.
 
Upvote 0

BEST TECH IN 2023

We've been tracking upcoming products and ranking the best tech since 2007. Thanks for trusting our opinion: we get rewarded through affiliate links that earn us a commission and we invite you to learn more about us.

Smartphones