"Problem" with creating CriminalIntent


#1

Just started Chap 7. When I went to create (ADT 22the CriminalIntent app I was presented with (in the Blank Activity window):

Fragment Layout Name

and then a window into which I can put a name in. It is initially filled in with: fragment_crime.

Not sure what to put in here (no option to not have this).

There’s also a pull-down window for Navigation Type. For that one I selected: None

In addition, Package Explorer now contains an: appcompat_v7 folder, not sure what that is.

Finally, when you open up CrimeActivity.java you get LOTS of new stuff, beginning with:

public class CrimeActivity extends ActionBarActivity

There is also now a “fragment_crime.xml”

I take it all this is new? I wasnt getting this before (just installed latest update to ADT).


#2

In the interest of completion… I went with accepting the Fragment Layout Name and everything seems to be OK. Including the fragment_crime.xml that was created. I’m still not sure about the appcompat_v7 folder and exactly how that plays and why it was created. I did find that if I exported by code you have to explicitly select the appcompat folder to export.

Finally, the thing that I found most strange was this ActionBarActivity instead of Activity. I did change that to FragmentManager and all seems OK.

Just curious if others have come across this new Fragment component when creating a new Android Project.


#3

When I change in CrimeActivity

on

( listing 7.1 )
and install on my devise I don’t get screen like on picture 7.13.
My screen is empty (without ActionBar with string “CriminalIntent”).
Is it depends on Android’s version?


#4

[quote=“DrJMun”]In the interest of completion… I went with accepting the Fragment Layout Name and everything seems to be OK. Including the fragment_crime.xml that was created. I’m still not sure about the appcompat_v7 folder and exactly how that plays and why it was created. I did find that if I exported by code you have to explicitly select the appcompat folder to export.

Finally, the thing that I found most strange was this ActionBarActivity instead of Activity. I did change that to FragmentManager and all seems OK.

Just curious if others have come across this new Fragment component when creating a new Android Project.[/quote]
Yes, lots of people are having trouble with this now. Check the forums for the early chapters for possible solutions.


#5

No luck in reverting to 22.3, and in reading stuff on the net even if it worked it could be problematic as there might be incompatibilities with the current version of SDK. I was hoping to find the complete bundle but no such luck. I guess Google doesnt want people going backward?


#6

You can definitely download the older SDKs. I think the question is how do you replace a newer one with the older one and it sounds like that’s where you ran into trouble. Some less recent Android resources talk about first installing Eclipse and then installing the SDK instead of installing them both at the same time. That might be one way to get it done. I’m working from memory but I think Reto Meier’s book “Professional Android 4 Development” describes that method of installation.

His book is older than the Big Nerd Ranch book, but makes an excellent companion book because his approach is pretty much the exact opposite of the Big Nerd Ranch book. The Big Nerd Ranch book is good but it moves very quickly and some critical points are make in just a sentence or too. Reto’s book moves slowly and tackles the material from an entirely different perspective, but if you are beginner like I am, Reto’s book will make zero sense on its own.


#7

Thanks, that was helpful. I havent had much luck trying to locate older versions. I guess I’ll stick with this and hopefully will not run into compatibility problems between the book and 22.6.


#8

I have just bought this book, and found a similar situation. So I have downloaded the source code and am using that instead of the code generated by the wizard. There are quite a few differences, but hopefully it will work out in the end. So for CrimeActivity.java I started with…

import android.os.Bundle;

import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentActivity;
import android.support.v4.app.FragmentManager;

public class CrimeActivity extends FragmentActivity {
    /** Called when the activity is first created. */
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_crime);
    }
}

The wizard creates the xml file for activity_crime.xml. There are a few lines you need to delete:

tools:context="com.bignerdranch.android.criminalintent.CrimeActivity" tools:ignore="MergeRootFrame"

You also have to change the fragment_crime.xml file as instructed in the book. All pretty straight forward.

Hopefully it’ll enable me to develop the app through the chapters…


#9

Possible solution - just use Empty Activity instead of Blank Activity while creating new project.


#10

I just checked the Android docs and it seems ActionBarActivity extends FragmentActivity, so you should just be able to leave it as is without having to do the renaming step in the book.

developer.android.com/reference … ivity.html

I am working though this book as a fairly new programmer and find that these minor problems can actually be quite helpful as it means I have to dig around a bit for solutions, making for a more thorough learning experience :slight_smile:


#11

It should be “caused” by the newer SDK. My way to solve the problem is creating an EMPTY activity instead of an BLANK one. This prevent the ActionBarActivity from appearing after “extent”. But the Generated appcompat_v7 is still there.