Go Back   Android Forums > Android Development > Application Development
Application Development Dev lounge for our application developers.

test: Reply
 
LinkBack Thread Tools
Old June 22nd, 2011, 11:35 AM   #1 (permalink)
New Member
Thread Author (OP)
 
Join Date: Jun 2011
Posts: 4
 
Device(s):
Carrier: Not Provided

Thanks: 0
Thanked 0 Times in 0 Posts
Default Vogella Tutorial

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.

Advertisements
BranMan is offline  
Reply With Quote
sponsored links
Old June 23rd, 2011, 12:29 AM   #2 (permalink)
Over Macho Grande?
 
alostpacket's Avatar
 
Join Date: Nov 2009
Location: NY
Posts: 7,920
 
Device(s): GlassXE, MotoX, N5, N4, N7'12, GNex, N1, SGT10.1, Revue, Xoom, Eris, OG Droid
Carrier: TMO

Thanks: 4,603
Thanked 3,578 Times in 1,530 Posts
Default

what is your package name?

can you post code to the manifest also?
alostpacket is offline  
Reply With Quote
Old June 27th, 2011, 03:25 PM   #3 (permalink)
New Member
Thread Author (OP)
 
Join Date: Jun 2011
Posts: 4
 
Device(s):
Carrier: Not Provided

Thanks: 0
Thanked 0 Times in 0 Posts
Default

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>
BranMan is offline  
Reply With Quote
Old June 27th, 2011, 07:10 PM   #4 (permalink)
Over Macho Grande?
 
alostpacket's Avatar
 
Join Date: Nov 2009
Location: NY
Posts: 7,920
 
Device(s): GlassXE, MotoX, N5, N4, N7'12, GNex, N1, SGT10.1, Revue, Xoom, Eris, OG Droid
Carrier: TMO

Thanks: 4,603
Thanked 3,578 Times in 1,530 Posts
Default

That looks correct assuming the public class
HelloPreferences

is in the de/vogella/android/preferences/ folder and has that as it's package name too

Edit:
Your second class need a . in front of the name so .Preferences
alostpacket is offline  
Reply With Quote
Old June 28th, 2011, 05:20 AM   #5 (permalink)
Over Macho Grande?
 
alostpacket's Avatar
 
Join Date: Nov 2009
Location: NY
Posts: 7,920
 
Device(s): GlassXE, MotoX, N5, N4, N7'12, GNex, N1, SGT10.1, Revue, Xoom, Eris, OG Droid
Carrier: TMO

Thanks: 4,603
Thanked 3,578 Times in 1,530 Posts
Default

also

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

should come after the /application tag and before the /manifest tag
alostpacket is offline  
Reply With Quote
Old June 28th, 2011, 02:01 PM   #6 (permalink)
New Member
Thread Author (OP)
 
Join Date: Jun 2011
Posts: 4
 
Device(s):
Carrier: Not Provided

Thanks: 0
Thanked 0 Times in 0 Posts
Default

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.
BranMan is offline  
Reply With Quote
Reply
Tags
activity, beginner, programming, tutorial, vogella


Go Back   Android Forums > Android Development > Application Development
Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On



All times are GMT -5. The time now is 01:33 PM.
Powered by vBulletin® Version 3.8.7
Copyright ©2000 - 2014, vBulletin Solutions, Inc.