In this tutorial I’ll show you how to fix Android Studio errors that you guys are having trouble with. I’ll also show how to pass objects between screens in Android.
I show how to set up Android Studio 0.8, show the files you need to install in the SDK Manager, and how to set up a working Android Virtual Device. I’ll also show how to fix the UIDs are inconsistent error. You can download Android Studio here. All the code used follows the tutorial below.
If you like videos like this, it helps to submit to Google Plus with a click here [googleplusone]
If you want a chance to win a Samsung Galaxy Note 3 and Galaxy Gear Smart Watch check out my new contest.
All of the Code from the Video
This code is in addition to the code covered in part 5 of my How to Make Android Apps tutorial.
build.gradle
apply plugin: 'android' android { compileSdkVersion 19 buildToolsVersion '19.1.0' defaultConfig { minSdkVersion 14 targetSdkVersion 19 versionCode 1 versionName "1.0" } buildTypes { release { runProguard false proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.txt' } } } dependencies { compile fileTree(dir: 'libs', include: ['*.jar']) compile 'com.android.support:appcompat-v7:19.+' }
Human.java
package com.newthinktank.switchingscreens.app; import java.io.Serializable; public class Human implements Serializable{ private double height, weight; private String name = ""; public Human(double height, double weight, String name) { this.height = height; this.weight = weight; this.name = name; } public double getHeight() { return height; } public void setHeight(double height) { this.height = height; } public double getWeight() { return weight; } public void setWeight(double weight) { this.weight = weight; } public String getName() { return name; } public void setName(String name) { this.name = name; } }
MainActivity.java
package com.newthinktank.switchingscreens.app; import android.content.Intent; import android.os.Bundle; import android.support.v7.app.ActionBarActivity; import android.view.Menu; import android.view.MenuItem; import android.view.View; import android.widget.TextView; public class MainActivity extends ActionBarActivity { @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); } @Override public boolean onCreateOptionsMenu(Menu menu) { // Inflate the menu; this adds items to the action bar if it is present. getMenuInflater().inflate(R.menu.main, menu); return true; } @Override public boolean onOptionsItemSelected(MenuItem item) { // Handle action bar item clicks here. The action bar will // automatically handle clicks on the Home/Up button, so long // as you specify a parent activity in AndroidManifest.xml. int id = item.getItemId(); if (id == R.id.action_settings) { return true; } return super.onOptionsItemSelected(item); } public void onGetNameClick(View view) { /*Intent getNameScreenIntent = new Intent(this, SecondScreen.class);*/ final int result = 1; // getNameScreenIntent.putExtra("callingActivity", "MainActivity"); Human bob = new Human(6.25, 185, "Bob"); Intent sendBob = new Intent(this, SecondScreen.class); sendBob.putExtra("humanBob", bob); startActivityForResult(sendBob, result); } @Override protected void onActivityResult(int requestCode, int resultCode, Intent data) { super.onActivityResult(requestCode, resultCode, data); TextView usersNameMessage = (TextView) findViewById(R.id.users_name_message); String nameSentBack = data.getStringExtra("UsersName"); usersNameMessage.append(" " + nameSentBack); } }
SecondScreen.java
package com.newthinktank.switchingscreens.app; import android.app.Activity; import android.content.Intent; import android.os.Bundle; import android.view.View; import android.widget.EditText; import android.widget.TextView; public class SecondScreen extends Activity{ @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.second_layout); Intent activityThatCalled = getIntent(); // String previousActivity = activityThatCalled.getExtras().getString("callingActivity"); Human bob = (Human) activityThatCalled.getSerializableExtra("humanBob"); TextView callingActivityMessage = (TextView) findViewById(R.id.calling_activity_info_text_view); callingActivityMessage.append(bob.getName() + " " + bob.getHeight() + " ft " + bob.getWeight() + " lbs"); } public void onSendUsersName(View view) { EditText usersNameET = (EditText) findViewById(R.id.users_name_edit_text); String usersName = String.valueOf(usersNameET.getText()); Intent goingBack = new Intent(); goingBack.putExtra("UsersName", usersName); setResult(RESULT_OK, goingBack); finish(); } }
Hey, derek,
I’m happy to say that I’m finally on board with your android tutorials. I was having issues installing updates to the android sdk on my windows computer, so I scalped it to get a Mac. However, I get this issue every time I try and run a program using the build in emulator:
WARNING: linker: libdvm.so has text relocations. This is wasting memory and prevents security hardening. Please fix.
pkg: /data/local/tmp/com.example.augustwhitlock.firstmacapp
Failure [INSTALL_FAILED_OLDER_SDK]
Do you have a solution for this?
Hi Derek, im a student and was on YouTube and saw how easy you explain your Android tutorials. I have been looking for an app I could make for my local police station, I just started getting interested in android development two months ago and having a lot of problems coding. I saw an app called nypd on Google play and its just want im looking for. Please help me development this app.PLEASE. I will constantly be on your YouTube channel learning more from you. Thank you
Hi Tay, Take a look at my Android for Beginners tutorials. It shows you how to make many complex Android apps with little to no coding experience. It also teaches you how to create regular Java Android apps. I hope it helps 🙂
Thank you so much Derek,app inventor is far more understandable. im just having problems with multiple screens and mapping out my location to the nearest station. and also creating a next screen photo gallery with details. do you have tuts for that.again thank you for helping us be better
As the tutorial continues I’ll do a ton on multiple screens. Stick with it and you’ll be making apps in no time.
Hey Derek, u r doing excellent work! Thank you for your videos!
May i ask for your help?
After upgrading Android Studio in 0.8 (Win 8.1 Pro, Jdk 1.7) my gradle went crazy :
In everything i do it goes like ” Gradle project refresh failed… Error:Protocol family unavailable”
Any help to that?
Thx in advance!
It is best to hold off on upgrades for Android Studio since it is still Beta. Downgrade and you should be fine. Always avoid canary builds and stick with developer builds.