Learn all the Java and Android skills you need to start making powerful mobile applications with practical and actionable steps
ISBN 139781789538502
Paperback766 pages
Paperback766 pages
Are you trying to start a career in programming, but haven’t found the right way in? Do you have a great idea for an app, but don’t know how to make it a reality? Or maybe you’re just frustrated that in order to learn Android, you must know Java. If so, then this book is for you.
This new and expanded second edition of Android Programming for Beginners will be your companion to create Android Pie applications from scratch. We will introduce you to all the fundamental concepts of programming in an Android context, from the basics of Java to working with the Android API. All examples use the up-to-date API classes, and are created from within Android Studio, the official Android development environment that helps supercharge your application development process.
After this crash course, we’ll dive deeper into Android programming and you’ll learn how to create applications with a professional-standard UI through fragments and store your user’s data with SQLite. In addition, you’ll see how to make your apps multilingual, draw to the screen with a finger, and work with graphics, sound, and animations too.
By the end of this book, you’ll be ready to start building your own custom applications in Android and Java.
After this crash course, we’ll dive deeper into Android programming and you’ll learn how to create applications with a professional-standard UI through fragments and store your user’s data with SQLite. In addition, you’ll see how to make your apps multilingual, draw to the screen with a finger, and work with graphics, sound, and animations too.
By the end of this book, you’ll be ready to start building your own custom applications in Android and Java.
- Master the fundamentals of coding Java for Android Pie
- Install and set up your Android development environment
- Build functional user interfaces with the Android Studio visual designer
- Add user interaction, data captures, sound, and animation to your apps
- Manage your apps’ data using the built-in Android SQLite database
- Find out about the design patterns used by professionals to make top-grade applications
- Build, deploy, and publish real Android applications to the Google Play marketplace
Howdy.
Was at the Packt site and they mentioned information was available at this site regarding using Android Studio with the Android Programming for Beginners.
Where may I find it or be emailed it?
Android Studio generates code differently to that which was generated at the time of writing the book. All the code provided will still work, just the starting point is different. Readers can see see a short discussion of how the latest version of Android Studio can be used with the book without too much trouble, at this next link. Scroll down to the comment posted on February 28th, 2016 at 3:02pm for details:
http://gamecodeschool.com/blog/android-programming-for-beginners/
Thanks,
Rey
Hi Rey,
Nice to hear from you and thanks for getting my book. The difference that causes a problem is that the new version of Android Studio doesn’t give an option to name the Activity class as described in the book and forces the class to be called MainActivity. Basically ignore the section in the book on naming the activity and Android Studio will auto-generate a working first app. All the rest of the code that you add in the first project (coding buttons etc) is unchanged. Although the text will reference HelloWorldActivity instead of the auto generated MainActivity and also another file that will be auto-named slightly differently. The next few projects in the book actually use the default activity name so will hopefully not cause you any bother.
The discussion referred to should give this link: http://gamecodeschool.com/books/learning-java-by-building-android-games-2nd-edition/
The discussion is in the context of a different book so the specifics are not relevant but the general discussion probably will be.
Please let me know if this doesn’t get you started and Ill answer your questions to get you making apps asap. Thanks again, John
Hi John,
I completed chapter 16 and I am attempting to run the code however I keep getting the following error:
Attempt to invoke virtual method ‘void androidx.recyclerview.widget.RecyclerView.setLayoutManager(androidx.recyclerview.widget.RecyclerView$LayoutManager)’ on a null object reference
I replaced all my code with the code example and I still get the same error. In MainActivity.java, the reference variable mLayoutManager is set to a new LinearLayoutManager which is why I am confused about the null object reference and how to fix it. How can this code be corrected to run the app?
Thank you!
Hi there and thanks for the question. The error is caused because recyclerView in MainActivity.java is null when the following line of code executes:
recyclerView.setLayoutManager(mLayoutManager);
This means that recyclerView was not initialized as it should have been when this line of code executes:
recyclerView = (RecyclerView) findViewById(R.id.recyclerView);
The cause is either that the call to setContentView isn’t correct and it should be if you copy and pasted the download because I just checked it. The other possibility is that your layout file activity_main.xml(did you copy paste that as well?) does not contain this line:
…include layout=”@layout/content_main” …
Or, that the content_main.xml file does not contain a RecyclerView instance with the id set to recyclerView.
Double check the preceding suggestions first as they seem most likely.
The only other thing I can think of that might cause this is if you have different versions of RecyclerView in the layout xml to that in the Java. Check the import statement in MainActivity.java is the same as this(Note the androidx in bold.):
import androidx.recyclerview.widget.RecyclerView;
And that in the content_main.xml file the RecylerView has a matching type like this:
…androidx.recyclerview.widget.RecyclerView
I think those steps should reveal the cause but if they don’t can you offer any more info from the Run/logcat window like some output or line numbers?
Good luck and let me know how you get on.
All the best,
John
Thanks so much, John! I typed all of the code the first time and got an error. I went back and copied and pasted some of the Java code in different classes thinking the error was there. The problem was exactly as you described that the activity_main.xml didn’t include the content_main layout. I’m not sure how that happened but your explanation is helpful for future reference if I ever get a similar error. Everything is working now!
Dear John, hi!
First of all, thank you very much for the book! It has been very helpful on my quest to learning Android and Java 😀
I am having trouble with one of the exercises, I’ve been trying to figure it out for a week now, but haven’t succeeded so far :/
On chapter 19 we built the “Dual Fragment” App. It has two main functionalities:
1) When in portrait mode, after clicking on one name it displays a new activity with the DetailFragment. That works perfectly.
2) When on Landscape mode it should display two fragments, side by side, and fill the right one with the details of the name that’s selected on the left one. I think that is the main issue.. Android seems to be trying to initialize the right fragment as soon as I turn the phone to Landscape. However, as nothing has been selected yet, it crashes.
The error is: ‘Attempt to invoke virtual method ‘int android.os.Bundle.getInt(java.lang.String)’ on a null object reference’
It occurs on the ‘AddressDetailFragment’ class on the following line:
‘int position = (int)getArguments().getInt(“Position”);’
Thank you very much in advance!
Hi Andres,
I have replied to your email to try and help with this. I think you must have the old version of the book.
John
Thank you very much for taking a the time to reply!! I deeply appreciate it 😀
Hi John,
I’d highly appreciate it if you could share the exact version of the “Android Studio” (AS) you used for screenshots when writing the second edition of “Android Programming for Beginners”.
I am new to Android Studio and Java so what I need is to just follow the instructions in the book without taking care too much (beyond the necessary) of AS. My key goal is to learn in practice the principles of the OOP – and the IDE is just a tool which for me now is a stumbling block.
I spent several hours downloading numerous AS versions available around the time the second edition was published (October 2018) but none of them had the same installation screens inluded in the book.
I was very hopeful about your book (style/approach) – but so far I am stuck and somewhat frustrated since “cutting corners” is not my approach.
I think this information could be in the errata available from Gamecodeschools.com/Packt.com (even though it’s not an error) and the exact version number of AS used in the book should be made available in its future editions.
Thanks!
Kind regards,
Max
Hi Max,
I have looked back through my notes and I can’t find this information. Is there some other way I can help you get started?
John
Hi John!
After several trials, I found that the AS version used at the time of the publication of the 2nd edition was the 3.2 Canary 17, filename:android-studio-ide-181.4823740-windows.zip, 64bit, available at https://developer.android.com/studio/archive.
This information is also in the book on the first screenshot in the “Our first Android app” section what I found only later.
My next stumbling stone is high local testing times (+/- 20 secs) despite my hardware specs being slightly better the tech specs from the book and a freshly reinstalled OS.
Could you please recommend some ways to test apps on remote powerful servers resulting in a shorter testing time?
Such long times do not incite to frequent testing – what is for me key in the learning process.
I also linked AS to Firebase and found it not intuitive – what adds to the complexity of AS/emulator/tablet handling by a beginner. But if Firebase is the only option I’d appreciate a link to a tried and tested tutorial.
Thanks!
Max
Hi Max and thanks for the information it will be useful to others.
I Have never had the need for remote dev/build. I use the time to stretch, or rest my eyes from the screen as I am getting creaky these days. You can often save build time using the “Apply code changes” options in the Run menu of Android Studio. You can read more about these options here: https://stackoverflow.com/questions/43488453/run-app-vs-apply-changes-android-studio-2-3
I have not used Firebase and if you are a complete beginner to Android it will definetely appear not intuitive. Firebase has tons of good features which you can mainly use for free but it will add significant complexity. I would master Android Studio before trying Firebase. However Firebase is the Google option and therefore most likely to be a good choice for the future.
Thanks,
John
Hi John,
thanks a lot for a great suggestion!
The processing time for both devices is visibly reduced.
In my quest for speeds similar to web browser HTML refresh, I was also considering Flutter but I believe comparable speeds are possible on much more powerful hardware than the one I have.
Basic IDE issues resolved I can be back in the book.
Thanks a lot for your willingness to help.
Max
Hi,
I am looking for the updates to the third edition of “Android Programming for Beginners” that are supposed to be here. It seems a lot has changed since the book has been written. Are there any updates available? It is hard to follow the book when everything looks different even in the very first chapter.
Thanks,
Andrea