dogriffiths / headfirstandroid Goto Github PK
View Code? Open in Web Editor NEWSource code for the book Head First Android Development by O’Reilly Media
License: MIT License
Source code for the book Head First Android Development by O’Reilly Media
License: MIT License
It appears as if the code isn't working in Chapter 13 because when using a dangerous service you explicitly need to ask for permissions from the user.
https://developer.android.com/training/permissions/requesting.html
I'm not sure where the code suggesting on the Android should go?
Could you possibly provide an example on how to resolve this issue?
Thanks
Updates to Android studio have broken some of the chapter projects. Currently I am stuck on Chapter 9 bits and pizzas, as the theme changes cause the app to crash. I can't find any answers for getting themes and action bar working with the projects, and future chapters continue working on the bits and pizzas app. Short of waiting for a new version of the book to appear, how can the projects be adjusted for current versions of Android Studio?
I was progressing through the book until the Link Fragments section of chapter 7. The onAttach is depricated but I changed that. The code included on the site doesn't appear to be updated.When I click on an activity the detail does not appear. The listener is null from what I can determine from the debugger.
Hello, I've been trying to work through the book, and have run into an issue i can't figure out. In both chapter six and seven i simply can not seem to make the fragments work. No bugs are reported within android studio, and the apps will even run, but as soon as i click on a button, such as drinks in the starbuzz app, the app immediately crashes. I assume this is a issue with fragments.
To be sure it was not my own inexperience that caused the issue, i have even tried to copy the exact files from the github, and the exact same issue occurs. My android studio is fully updated, and i have followed all the advice i have found online, but still, same issue.
A NullPointerException may occur in DrinkCategoryActivity.java from Chapter 12 after calling the onDestroy() method if "cursor" or "db" objects are null (e.g., after rotating the device when having the Drink Categories list on screen).
@Override public void onDestroy() { super.onDestroy(); cursor.close(); db.close(); }
Need to do a null check on variables "cursor" and "db".
Using even the latest code, the stopwatch gets reset to 0 each time I rotate the tablet emulator.
It also happens when I use the phone emulator.
Hello Sir
I am trying to open pasta card view with image and text as the pizza work , but I am having trouble. can you help me, or someone can help me.
Your Starbuzz cafe project was a very useful lesson that taught me how to use a number of methods. It also is a prototype for an ordering app, something that is much needed in supply and sales industries.
One very important thing I couldn't figure out is how to create a working set of subcategories. Your project only features 3 items in the top category. Can you show us how you would fill out the 2 other categories? I built a project that attempt this by adding categories as a column to the table I had to uncomment quite a few of your checks and, ultimately, the top category wouldn't display anything after I removed the position ==0 check. Items displayed in the additonal categories I added to the array.
Here's a snippet:
// if (position == 0) { //commented this out because nothing would display except top category.
Intent intent = new Intent(TopLevelActivity.this,ItemCategoryActivity.class);
intent.putExtra(ItemCategoryActivity.CATEGORYID, (int)id);
startActivity(intent);
and
cursor = db.query("InventoryItem",
new String[]{"_id", "NAME"},
"categoryId = ?",
new String[] { Long.toString(categoryId) },
null, null, null, null);
When I try running the app after creating the WorkoutListFragment class and adding it to the Activity_Main_XML, on my device, I get an error message and the app is terminated immediately. I have check the code, and it is correct, the same thing happens when I run it in the Emulator. I do not know what the problem is.
Hi,
I followed the steps in the book to run the sample code provided by AndroidStudio, but when AVD running, the "MyFirstApp" did not show up. And the console did not show the same output as the book's
The output of my console
emulator: WARNING: VM heap size set below hardware specified minimum of 128MB
emulator: WARNING: Setting VM heap size to 384MB
Hax is enabled
Hax ram_size 0x60000000
HAX is working and emulator runs in fast virt mode.
console on port 5556, ADB on port 5557
When requesting permission for ACCESS_FINE_LOCATION, Android has declared this as "Protection Level: Dangerous", which means that starting with Android Marshmallow, the app must explicitly ask the user for permission before it can be used.
Because there wasn't a request for permission, this app crashes immediately on devices running Android Marshmallow. I have a solution that I believe is working correctly here: https://github.com/TBVanderley4545/Odometer.git. I added checkSelfPermissions in onCreate and onStart in MainActivity.java and implemented onRequestPermissionResult. I also added checkSelfPermission in OdometerService.java in onCreate() and onDestroy().
Thank you for writing your book. It's been a great help.
The workout list appears when I open the app, but the app crashes when I select a specific workout. I have followed the code exactly as it is in the 2nd edition book from Chapter 11. The app worked fine in Chapter 10, it's just not working after making changes for the stopwatch. I also am not getting any error messages when it crashes. I am using Android Studio 3.3.1. Any idea what could be going on?
I'm unable to use name="AppTheme" parent="Theme.Holo.Light"
or
<style name="AppTheme" parent="Theme.Material.Holo">
ERROR:
Cannot resolve symbol
Validate resource references inside Android XML.
It seems as though the 2 themes required in this chapter aren't available with
import android.app.Activity;
I get the same error when I download your source files from GIT and attempt to run them. Do you know what substitute them I should I run in order to complete this chapter?
Even though I'm extending Activity Intelisense is only showing AppCombat themes in the styles.xml.
In Stopwatch, do you assume onPause()
or onStop()
is called before onSaveInstanceState()
? That's where you set wasRunning
.
As you know, onSaveInstanceState()
may be called before or after onPause()
& always before onStop()
.
See:
After entering all the code fore the fragment, I get a warning in the XML file on all the buttons about the onClick reference line:
Cannot resolve symbol 'onClickStart' (the same with the onClickStop and onClickRest)
Checks if the related method specified on the onClick XML attribute is declared in the related activity.
all the onClick handlers are present in the code exactly like in the original Stopwatch Activity.
for some reason it looks fore the onClick in the activity not the fragment, because I tried to use the code correction in the XML file but it only suggested the activity's not the fragments, and when I tried telling it to put it in the fragment I got a warning: "Stopwatch fragment is not acceptable" and the problem was not resolved.
import android.support.v7.app.ActionBarDrawerToggle;
is now deprecated.
Is there a workaround for this? I'm unable to use it in Chapter 10.
Hi, img links are broken on readme
I am using the codes from chapter 12 starbuzz app, but if we tap on Drink in top category, the DrinkCategoryactivity(ListActivity) doesn't populate the UI with the drink values from the database using SimpleCursorAdapter
I have debug it many times, but didn't able to identify the bug. Please help me reslove this issue
Finaly managed to complete your book and all the projects..
It was a very good course.
Now i want to combine the different chapters and this is wat i find:
of course i want to use a database so i make a SQLiteOpenHelper class
an then i want to make this work together with fragments. guess what, they dont want to work together because fragmens dont accept context.
So, pease tell me how to adapt a database to the workout app or to the bitsandpizza app
I own the Book. It is of great help. I am interested in using all or parts of delayedmessageservice.java in my app. Is this open source, is there any license requirements.
s/"That’s write"/"That's right" on the page at https://github.com/dogriffiths/HeadFirstAndroid/wiki/How-Android-Apps-are-Built-and-Run
I imported the Stopwatch project from chapter 4 into Android Studio, but it creates an error: "Grade project sync failed. Basic functionality (e.g., editing, debugging) will not work properly." Any ideas on how to fix this?
Hi,When i read about Activity lifecycle in chapter 4,your book said when an Activity is paused and then rotated,how is the lifecycle going? Here i add a new button to StopWatch app,and when click the button,start a new Activity,and the new Activity‘s theme is Theme.Dialog,so when start the Activity,my StopWatchActivity is in onPause method,at this moment,I rotate my device,onStop->onDestroy->onCreate->onStart->onResume->onPause is called,but the book said onResume is not called,how to understand this?
With the fix code from the section "Rotating the device breaks the app", there's still a rotation bug.
Put a few items in the back stack, rotate the device twice, then go through the back stack. Everything is defaulting to the 0 index item.
The problem is Fragment.onCreateView() only gets called for the visible fragment. So when you rotate it the second time, the hidden fragments don't have the proper value to write to the bundle, and end up writing 0.
I moved the code to retrieve the value from the saved Bundle to onCreate(), which gets called for the hidden and visible fragments, and it functions properly.
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.