Skip to main content

Posts

Showing posts with the label Android for begginner

Simplify Your Tax Calculations with GST Calculator 2024: The Ultimate Tool for Businesses and Individuals

onBackPressed() method is deprecated, you are looking for an alternative? Here It is the Latest Solution in android | Kotlin

With the evolution of Android development, several APIs and functions get deprecated over time to make way for more robust and flexible alternatives. One such deprecation that developers need to be aware of is the onBackPressed() method in Android. In Android, onBackPressed() was commonly used to handle back button presses within an activity. However, with the introduction of the Jetpack libraries and the emphasis on more structured navigation, this method has been deprecated. This blog will explore why onBackPressed() is deprecated and what the best alternative solutions are in Kotlin for handling back navigation. Why onBackPressed() is Deprecated The primary reasons for deprecating onBackPressed() include: Improved Navigation Architecture: Android Jetpack's Navigation Component provides a more consistent and predictable way to handle navigation, including back navigation. Lifecycle Awareness: Handling back...

Mastering Kotlin Generics: Understanding and Deep Dive of In, Out, and Where

Kotlin, a modern statically typed programming language, offers many powerful features to streamline coding, one of which is its support for generics. Generics enable you to write flexible and reusable code, allowing types to be parameters when defining classes, interfaces, and functions. Understanding the intricacies of generics is crucial for leveraging Kotlin's full potential. In this blog, we'll delve into the concepts of in , out , and where in Kotlin's generics. What Are Generics? Generics are a feature that allows you to define classes, interfaces, and methods with placeholder types. This way, you can create more flexible and reusable components. For instance, you can create a List<T> that can hold any type T , rather than creating separate classes for each type. class Box<T>(val value: T) fun main() { val intBox = Box(1) val stringBox = Box("Hello") } In this example, Box<T> is a generic class where T ...

A Comprehensive Guide to Setting Up a Room Database in Android Studio | Android Development

Setting up a Room database in Android Studio involves several steps. Room is an abstraction layer over SQLite, which makes it easier to work with databases in Android apps. Here's a basic guide to setting up a Room database: Add Room Dependencies: Open your app-level build.gradle file and add the following dependencies:  implementation "androidx.room:room-runtime:2.4.0" annotationProcessor "androidx.room:room-compiler:2.4.0" Make sure you are using the latest version of Room library. You can check for the latest version on the official website : https://developer.android.com/jetpack/androidx/releases/room Define Entity: An Entity represents a table within the database. Create a class for your entity/tables. Annotate the class with @Entity and specify its properties as columns. import androidx.room.Entity ; import androidx.room.PrimaryKey ; @Entity (tableName = "your_table_name" ) public class YourEntity { @PrimaryKey (autoGenerate...

How to Insert Multiple rows in a single db transaction in Android Room Database? | Android | Room DB

  To insert multiple rows into a Room database in Android, you can follow these steps: 1. Set up Room Database: First, make sure you have set up your Room database correctly in your Android project. Define your Entity class, create a Database class that extends RoomDatabase, and set up your DAO (Data Access Object) interface. 2. Create Entity Class: Define an Entity class that represents the data you want to insert into the database. For example: 1 2 3 4 5 6 7 8 9 @Entity (tableName = "my_table" ) public class MyEntity { @PrimaryKey (autoGenerate = true ) public int id; public String name; public int age; // Add other fields and getters/setters as needed } Create DAO: Create a DAO interface with a method to insert multiple rows. For example: 1 2 3 4 5 @Dao public interface MyEntityDao { @Insert void insertAll (List<MyEntity> entities); } Initialise Database and DAO: In your application code, create an insta...

SearchView in Android with RecyclerView | Toolbar | Kotlin

 The search functionality in android App is a very important feature of any list page. In this article I make a simple android application to describe the SearchView integration in Android with RecyclerView | Toolbar | Kotlin. Follow the steps- Step 1 :  First create a blank project in android studio with simple empty activity. Step 2 :  Use the below code in colors.xml file <?xml version="1.0" encoding="utf-8"?> <resources> <color name= "purple_200" > #FFBB86FC </color> <color name= "purple_500" > #FF6200EE </color> <color name= "purple_700" > #FF3700B3 </color> <color name= "teal_200" > #FF03DAC5 </color> <color name= "teal_700" > #FF018786 </color> <color name= "black" > #FF000000 </color> <color name= "white" > #FFFFFFFF </color> </resources> Step ...

How to compare between two JSON online.

 In many times in our development time we need to compare between two JSON Object are equal or not. For simple JSON Object which has contain with 3-4 key-value pair is easy for us to compare it by us, but for complex JSON it is very difficult two compare between them. So in this article I show you how you easily compare between two JSON. For that case you need to visit  http://www.jsondiff.com/ As example, Using this site we compare between two json object Sample JSON 1 { "name" : "John Doe" , "roll_no" : "25" , "is_present" : true } Sample JSON 2 { "name" : "John Doe" , "roll_no" : "25" , "is_present" : false , "div" : "A" } So first we open the site and in left and right side input box just copy paste the sample JSON 1 and sample JSON 2 and click on the "Compare" button which placed in centre. Now you can easily see the difference as per ...

How to check internet availability in kotlin | Android

 Internet availability check for any standard application is necessary. When you call an Rest API or any internet related task execution, you must need to check the internet availability in your application. So In this article, I show you how to check the internet availability in android | Kotlin  So, First in your project add the INTERNET and ACCESS_NETWORK_STATE permission in menifest.xml <uses-permission android:name= "android.permission.INTERNET" /> <uses-permission android:name= "android.permission.ACCESS_NETWORK_STATE" /> Make a function in kotlin, that return true if internet connection is available else it return false fun isOnline (context: Context): Boolean { val cm = context.getSystemService(Context.CONNECTIVITY_SERVICE) as ConnectivityManager val activeNetwork: NetworkInfo? = cm.activeNetworkInfo return activeNetwork?.isConnectedOrConnecting == true } Now, simply you c...

Create Any Recyclerview Adapter within 5 seconds, in Android | Kotlin.

 In every single android application, we need to make many number of recycler-view adapter. So every time you create a blank adapter and modify it as per your requirements. But it is very boring and as well as time taking. So here I give you a solution that you can create any recyclerview adapter within 5 seconds using file template in Android Studio. So, Lets read this full article- First we open android studio and create a project. After project creation  Open File->new->Edit File Template... Follow this below screenshot Okay, After click on "Edit File Template" a popup is open "File and Code Template", Now click on the  " + " icon and set set your template name. Now set your template name, template extension and template body. after doing everything click on "Apply" and then click on "OK" The template body I after after the screenshot Template Body Copy this code and paste it on the template body section, which I marked in scre...

Popular posts from this blog

Create Any Recyclerview Adapter within 5 seconds, in Android | Kotlin.

 In every single android application, we need to make many number of recycler-view adapter. So every time you create a blank adapter and modify it as per your requirements. But it is very boring and as well as time taking. So here I give you a solution that you can create any recyclerview adapter within 5 seconds using file template in Android Studio. So, Lets read this full article- First we open android studio and create a project. After project creation  Open File->new->Edit File Template... Follow this below screenshot Okay, After click on "Edit File Template" a popup is open "File and Code Template", Now click on the  " + " icon and set set your template name. Now set your template name, template extension and template body. after doing everything click on "Apply" and then click on "OK" The template body I after after the screenshot Template Body Copy this code and paste it on the template body section, which I marked in scre...

How to fetch Latitude, Longitude from address and vice-versa(address from Latitude, Longitude) using Google Geo coder SDK in android| Kotlin

 In this Android development related article, you will get a simple solution that, how to get address using Latitude, Longitude and vice-versa. i.e latitude, longitude from an address text. It is very easy and simple. Read full article and carefully follow all the steps. Here we use google Geocoder SDK. Okay, first we create an android project in kotlin and create an Activity say MainActivity.kt. Use the below code- Function get Latitude, Longitude from Address- fun getLatLngFromAddress (context: Context, mAddress: String): String { val coder = Geocoder(context) lateinit var address: List<Address> try { address = coder.getFromLocationName(mAddress, 5 ) if (address == null ) { return "Fail to find Lat,Lng" } val location = address[ 0 ] return " Latitude: ${location.latitude}\n Longitude: ${location.longitude}" } catch (e: Exception...

How to consume REST APIs in Laravel | Laravel Development | Solution

In Laravel, you can call a REST API using the HTTP client provided by the framework. Laravel's HTTP client allows you to make GET, POST, PUT, DELETE, and other HTTP requests to external APIs. Here's how you can call a REST API in Laravel: Install Laravel (if not already done): If you haven't already set up a Laravel project, you can create one using Composer by running the following command: composer create - project -- prefer - dist laravel / laravel project - name Create a Controller (optional): You can create a controller to encapsulate the API call logic, but this step is not strictly necessary. You can also make API calls directly from your routes or other parts of your application. To create a controller, run the following command: php artisan make: controller ApiController Make an API Request: You can make API requests using Laravel's HTTP client, which is a fluent, expressive interface for making HTTP requests. Here's how you can make a simple GET request t...