Android
Install Parse SDK
18 min
install parse sdk on your android studio project introduction in this section you learn how to install parse android sdk into your android studio project this tutorial uses a basic app created in android studio arctic fox 2020 3 1 patch 1 with compilesdk 30 , minsdk 21 and targetsdk 30 at any time, you can access the complete android project built with this tutorial at our github repositories kotlin example repository java example repository goal learn how to install parse sdk on your android project prerequisites to complete this section, you will need an app created at back4app note if you don’t have an app now please follow the new parse app tutorial to learn how to create a parse app at back4app android studio basic android app note if you don’t have a basic app created you can follow the create a project tutorial from android studio official website note parse android sdk works with compilesdk 27 and targetsdk 27 or higher 1 install sdk we need to implement parse sdk to our android project for this we will use gradle , an open source build automation tool that is designed to be flexible enough to build almost any type of software android studio uses gradle for build process and import external libraries like parse sdk 1 in your android studio project, open your settings gradle file now we will add jitpack to our project jitpack is a package repository for jvm and android projects 2 now we need to add maven {url 'https //jitpack io'} line to repositories{} tag in the settings gradle file 1 repositories { 2 3 4 maven { url 'https //jitpack io' } 5 } 3 it’s also necessary to look in the android{} tag if your compilesdk is 27 or higher and also if your targetsdk is 27 or higher if they aren’t, you must change these versions to 27 or higher, otherwise your parse sdk for android may not work properly after checking this, your build gradle (module\ app) should look like the one in the image below 4 if all previous steps are set now we are able to add parse android sdk to our project implementation "com github parse community parse sdk android\ parse" in dependencies{} tag change the latest version here value with version of your choice it will look like this you can see current version of sdk in here sdk versions 5 now we need to sync our build gradle to last changes to effect our project to learn more about adding support libraries to your android studio project, see the android studio’s support library setup page 2 connect to back4app now it is time to use android parse sdk in action we need internet access and server credentials to connect to back4app to use parse sdk, our application need to have access to the internet network to allow our app to have it, we need to grant permissions in the androidmanifest xml file also, we have to set up the app’s credentials to connect our app to back4app for achiving this we need to follow the steps below 1 go to app > manifests > androidmanifest xml in your android studio project 2 now, before the application tag in the androidmanifest xml file, copy the following code snippet 1 \<uses permission android\ name="android permission access network state"/> 2 \<uses permission android\ name="android permission internet"/> 3 inside the application section of the androidmanifest xml file, add the following code 1 \<meta data 2 android\ name="com parse server url" 3 android\ value="@string/back4app server url" /> 4 \<meta data 5 android\ name="com parse application id" 6 android\ value="@string/back4app app id" /> 7 \<meta data 8 android\ name="com parse client key" 9 android\ value="@string/back4app client key" /> 4 go to app > res > values > strings xml file 5 in the strings xml file, add the following code 1 \<string name="back4app server url">https //parseapi back4app com/\</string> 2 3 \<! paste both strings as required > 4 \<string name="back4app app id">paste your application id here\</string> 5 \<string name="back4app client key">paste your client key here\</string> 6 leave the string xml opened and go to back4app website now you will find your keys to replace in the code go your dashboard and then click on app settings > security & keys 3 initialize parse sdk in our app in this step we will complete the parse initialization using app id and client key which we have obtained at the end of step 2 we recommend you to write the installation codes in the app java or app kt files which you will create the reason for this, to ensure that our parse sdk initialize codes will work before any other activity or context, application context is the first that creates and last destroy so, create the app javain the same folder as your mainacitivty, and then follow the steps below 1 import parse library to your app file 1 import com parse parse; 2 inside app file call the following code app java 1 public class app extends application { 2 @override 3 public void oncreate() { 4 super oncreate(); 5 parse initialize(new parse configuration builder(this) 6 applicationid(getstring(r string back4app app id)) 7 clientkey(getstring(r string back4app client key)) 8 server(getstring(r string back4app server url)) 9 build()); 10 } 11 } app kt 1 class app application() { 2 override fun oncreate() { 3 super oncreate() 4 parse initialize( 5 parse configuration builder(this) 6 applicationid(getstring(r string back4app app id)) 7 clientkey(getstring(r string back4app client key)) 8 server(getstring(r string back4app server url)) 9 build()); 10 } 11 } please check the image below as an example using java we put our code to oncreate() method because we want to connect to our server first before taking any other action don’t forget to define this file in the androidmanifest xml for doing this, go to the androidmanifest xml file and add the following line of code inside the applicationtag android=" app" at the end, your androidmanifest xml should look like this if the name of the java file that extends application that you created on the previous step isn’t “app”, don’t forget that the code above should have the correct name of the file (android\ name=" name of the file") 4 test your connection to test your connection with parse sdk, let’s save an object in the mainactivity of your android studio project 1 go to your android studio project and add the following code to your oncreate() method in order to save your first parse object of the application into your dashboard app java 1 public class mainactivity extends appcompatactivity { 2 @override 3 protected void oncreate(bundle savedinstancestate) { 4 super oncreate(savedinstancestate); 5 setcontentview(r layout activity main); 6 parseobject firstobject = new parseobject("firstclass"); 7 firstobject put("message","hey ! first message from android parse is now connected"); 8 firstobject saveinbackground(e > { 9 if (e != null){ 10 log e("mainactivity", e getlocalizedmessage()); 11 }else{ 12 log d("mainactivity","object saved "); 13 } 14 }); 15 } 16 } app kt 1 class mainactivity appcompatactivity() { 2 override fun oncreate(savedinstancestate bundle?) { 3 super oncreate(savedinstancestate) 4 setcontentview(r layout activity main) 5 val firstobject = parseobject("firstclass") 6 firstobject put("message","hey ! first message from android parse is now connected") 7 firstobject saveinbackground { 8 if (it != null){ 9 it localizedmessage? let { message > log e("mainactivity", message) } 10 }else{ 11 log d("mainactivity","object saved ") 12 } 13 } 14 } 15 } 2 launch your app and go to back4app website find your app and go to its dashboard 3 now click on database > browser > first class you should see the first class with an object, as shown in the image below it’s done! we completed the section! now you have learned how to install the parse sdk in your application learn more by walking around our android tutorials