Skip to main content

Posts

Showing posts from January, 2020

JSON Rest API in Android

How to use JSON Rest API in Android App Hello guys, Today we are going to see how we can consume JSON API in Android or we can say consume REST API in Android. First, let's see what is REST API? According to restfullapi.net :  REST is acronym for  RE presentational  S tate  T ransfer. It is architectural style for  distributed hypermedia systems  and was first presented by Roy Fielding in 2000 in his famous  dissertation . So basically we can fetch data and create data on the server. Now let's make a working example on JSON API. First, we have to create a new project in the android studio if you already not created it. Our end result app will look like this. To make this UI, we are using android recyclerview and cardview. To use them we need to add the dependency to our project. After adding the dependency hit the sync button. We need internet permission as we will fetch the data from the internet. For demo pur

How to test app without android emulator

How to test Android Applications without Emulator Today we are going to see how we can test our android applications instead of using emulator we can use our real device . To use the real device for testing we need to connect our device with our pc, to do that we have 2 choices. The first choice is by using USB cable we can connect our real device to pc and the second method, which is my favorite, that we can connect our device wirelessly (No use of USB or any cable). Let's see how we can do these methods one by one. To perform these methods first we need to enable USB Debugging from the developer options. Go to the system settings and go at the last there is an option called developer option like below. If there is no option is showing then you have to unlock this option by going to about phone option then click on software information and then click quickly 5 to 6 times on build number label. Now you able to see the developer option. After clicking the

Snackbar in Android

How to make Snackbar in Android Today. we are going to learn how to make a Snackbar in Android . There are many ways to show short information but generally, we use toast messages and we have a snackbar. Before going to implementation we should know the difference between the toast and snackbar. If you want to show the only information then you should use toast but if you want to show some information with some action to be performed then it is recommended to use a snackbar with action . You can customize the position of toast but the snackbar only shows from the bottom of the screen. Now let's see how we can make a simple snackbar and also snackbar with the actin button. How to make a simple snackbar? Let's start by making a new project in the android studio if you not created already. After that, we need to add a dependency to our project. Add this dependency and hit the sync button. After adding the dependency, go to the activity xml file

LocalBroadcastManager in Android

What is LocalBroadcastManager and How to use LocalBroadcastManager in Android Today, we are going to learn what is localbroadcastmanager and how to use it our application. Let's start. Whats is LocalBroadcastManager?  Just like Global Broadcast receiver where we receive various broadcasts from different applications.  For example, we can the listener broadcast for battery percentage when it very low or we can set various listeners for various events. We can also make our custom broadcast and can set the receiver from other applications and can communicate between different applications. But what if you only want that your custom broadcast can only listen within the application to pass some sensitive data something like user data or some transaction information. The problem with global broadcast is that it is system-wide and can be vulnerable which can be very harmful especially when we are working with some sensitive data. By using local b

Twitter Like Button in Android

How to make Twitter like button in Android Today, we gonna learn how to make like button the same as Twitter has on their website with animation. See the below gif. Let's get started. First, create a new project in Android Studio if you not created already. After creating the project, we need to add some dependencies to our project. So first, open your build.gradle (Project: <app_name>) file and add below line in allprojects repositories section as shown below. Now after that, we need to open our build.gradle (Module: app) and this dependency. This is all our dependency part. Now hit the sync now button at the top right corner. This will add the dependency in our project.  Now we can move forward and open an activity xml file and this code in our layout for the like button. Our activity xml file has ConstraintLayout as parent layout so we have to add constraints attributes. As you can see in our like button we

Load Image from URL in Android

How to show/load Image from URL in Android App Today, we are going to learn how we can load or show an image from the internet or URL or link and show it in the ImageView in your android app. Let's start by creating a new android project. After creating the project we have to add our dependency to the app level Gradle file. Open your build.gradle (Module: app) and add these dependencies After adding the dependencies, hit the sync now button at the top right corner. This will add the glide dependency in your project. Now open your activity xml file and add an ImageView. Like this. We have a ConstraintLayout as parent layout and in the ConstraintLayout, we have a child ImageView and we set its id imageView. Now open your activity java file, and add this code in your onCreate method. In the above code, first, we are getting our image view from xml by using findViewById. And then, we are calling the  glide library , and it's with function and pa

Shared Preferences Android

What is Shared Preferences and How to use it in Android What is Shared Preferences in Android? If you want to save data all across your application then Shared Preferences  may be your choice. You can save data by using Shared Preferences  and access the data anywhere in your application.  Shared Preferences data is associated with your application and if the user uninstalls the app or clears its data from the mobile setting, then you will lose the data. Enough talking, now see how you can use Shared Preferences ? How to use Shared Preferences? First, let's create a new project in the android studio. So we will make two activities where we will save data in the first activity and show saved data in the second activity. In the first activity xml, we will add an EditText, a Button to save trigger save data and another one Button to go to the second activity. See the below code. Now, go to the first activity java file and make shared preferenc

Pass Data between Activities

How to pass data from one activity to other activity Today, we are going to see how we can send data from one activity to the second activity. So let's get started, First, create a new project if you do not create already. Then open your first activity xml file and we are going to add a button. This button will be our trigger to open the second activity. So to do that we need to create a button and set on click listener. Remove textview created by the android studio by default and add a new button like the below image. Note that I have changed my parent layout from ConstraintLayout to LinearLayout which is optional. I have specified id to the button e.g openAcitivityButton. Now it's time set click listener. To do that we need to open our activity java file. In the above code, we initialize our button name it as openActivityButton with its's id and then we are calling method setOnClickListener in the onCreate method.

Image Slider in Android with library [Easy and Fast Implementation]

How to make Image Slider in Android App How to make image slider in android Today, I am going to show you how you can make a decent image slider in your android app very easily without writing lots of code. check this gif below for end result what we will be going to make. is it look beautiful? To make this type of image slider or image carousel . Follow these simple step which is given below. First, of course, you have to create a new project in android studio. Choose an empty activity and then choose the app name and hit the finish button. Wait for some time to build your project and after the build. Move your images to your drawable folder. here as you can see, I have move 3 images name img1, img2 and img3. After this, now we have to add our dependency for image slider. Add this dependency in your build.gradle(app) file After adding the dependency hit the sync now button (top right corner). Now go to the activity xml file. Remove Textvi