Posts

Showing posts from May, 2023

Learning Journey#4. Understanding REST APIs: for Beginners

Image
Welcome to the "Learning Journey" series. This space is my personal archive where I share insights and discoveries from my explorations into new tech territories, particularly back-end development and cloud services. As I continue to broaden my tech understanding, I hope this series inspires and contributes to your own learning journey. Introduction https://uxwing.com/rest-api-icon An API, or application programming interface, is a way for two pieces of software to communicate with each other. REST, or Representational State Transfer, is a set of architectural principles for designing APIs. REST APIs are the most common type of API and are employed in a wide array of applications, such as web browsers, mobile apps, and server-to-server communication. What is a REST API? A REST API is an API that adheres to the REST architectural principles. These principles dictate how

Learning Journey #3. Spring Framework

Image
Welcome to the "Learning Journey" series. This space is my personal archive where I share insights and discoveries from my explorations into new tech territories. we're going to dive into a game-changer in the world of Java-based enterprise applications: the Spring Framework. 1. Background: The Evolution of Spring At the beginning of enterprise Java, EJB (Enterprise JavaBeans) was the dominant choice for building robust enterprise applications. However, the complexities of EJB did not blend well with modern architectural trends, which required a simpler, more lightweight solution. This need led to the birth of the Spring Framework. Over time, Spring has evolved from a remedial framework to combat the complexities of EJB to a comprehensive suite of projects addressing a wide array of enterprise Java needs. It now includes everything from a security framework to a full-fledged MVC web application framework. 2. Understanding the Spring Framework

Daily#14. Understanding JVM, Dalvik, and ART: The Engines Behind Java and Android Applications

Image
Introduction Developing applications in Java or for the Android platform requires an understanding of the runtime environments where these applications run. A runtime environment refers to the state of the system when a program is executed. It includes the settings, libraries, and other supporting infrastructure that the system provides to the program. Understanding runtime environments is crucial as they dictate how a program will behave when executed. Java Virtual Machine (JVM) is the original runtime environment for Java, but is not used on Android. Dalvik and ART, on the other hand, are newer runtime environments that were specifically designed for Android. This post will guide you through the functionality of JVM, Dalvik, and ART. What is JVM? The Java Virtual Machine (JVM) is an abstract computing machine that enables a computer to run a Java program. Here are the key characteristics of JVM: https://en.wikipe

Daily #13: Diving Deeper Into Android Events: Location Tracking, Screen On/Off, Orientation Changes, Battery Status, Incoming Calls/SMS, and Pedometer

Welcome back to our daily tech series! Today, we're delving deeper into some essential Android events and features that you can implement in your apps to enhance user experience. Let's get started. Location Tracking Android provides the LocationManager for accessing system location services. This lets your app request location updates from GPS or network providers. Here's an example: LocationManager locationManager = (LocationManager) getSystemService(Context.LOCATION_SERVICE); Criteria criteria = new Criteria(); criteria.setAccuracy(Criteria.ACCURACY_FINE); String bestProvider = locationManager.getBestProvider(criteria, true); LocationListener locationListener = new LocationListener() { public void onLocationChanged(Location location) { // Called when a new location is found by the network location provider. // Do something with the location. } // Override other methods as needed }; // Request location updates locationManager.requestLocati

Daily#12: Networking in Android - Understanding ConnectivityManager and Network APIs

Hello everyone! Today, let's delve into Android's networking capabilities. We'll concentrate on the ConnectivityManager class and the Network API, both of which provide applications the means to specify a network interface for communication with external networks. ConnectivityManager and bindProcessToNetwork Let's start with ConnectivityManager, a class that provides network connectivity status and updates applications when this connectivity changes. One crucial method in this class is bindProcessToNetwork. ConnectivityManager cm = (ConnectivityManager) getSystemService(Context.CONNECTIVITY_SERVICE); Network network = ... // Your desired network cm.bindProcessToNetwork(network); Using bindProcessToNetwork, an application can dedicate a Network object for its network traffic. Therefore, all traffic from the application will be routed over this specified network. Acquiring a Network Object You may be wondering how to get a Network object to use with bindProcessToNet

Learning Journey#2: Docker and Kubernetes: A Journey into Containerization and Orchestration

 Welcome to the "Learning Journey" series. This space is my personal archive where I share insights and discoveries from my explorations into new tech territories. Today, we're diving into Docker and Kubernetes - two essential tools for modern software development. 1. The Need for Efficient Software Deployment In our digital era, software deployment is a critical aspect of delivering value to users. However, traditional deployment methods have their shortcomings - compatibility issues across different environments, longer development cycles, difficulties in managing and scaling applications, to name a few. 2. Introducing the Solution - Containerization To address these issues, the concept of "containerization" comes into play. Imagine packing your application and all its dependencies into a box (or "container") - this way, you can be sure it will work the same way, no matter where you open it. 3. Unveiling Docker - Master of Containers Welcome Docker

Daily#11. Establishing Wi-Fi Connection using WifiNetworkSpecifier and WifiNetworkSuggestion

 Welcome back to our daily tech series! Today, we're diving into how to connect to a Wi-Fi network programmatically in Android using WifiNetworkSpecifier and WifiNetworkSuggestion APIs. WifiNetworkSpecifier WifiNetworkSpecifier is a part of the Android 10 (API level 29) addition to the Wi-Fi API. It allows applications to force Wi-Fi connections with specific networks programmatically. However, please note that the system will limit the number of outstanding requests to 100 per app. If this limit is exceeded, an exception will be thrown. Here's a simple example of how to use it: WifiNetworkSpecifier specifier = new WifiNetworkSpecifier.Builder() .setSsidPattern(new PatternMatcher("test", PatternMatcher.PATTERN_PREFIX)) .setWpa2Passphrase("test1234") .build(); NetworkRequest request = new NetworkRequest.Builder() .addTransportType(NetworkCapabilities.TRANSPORT_WIFI) .setNetworkSpecifier(specifier) .build(); ConnectivityManager connecti

Learning Journey #1: Unraveling the Microservices Architecture

Welcome to the "Learning Journey" series. This space is my personal archive where I share insights and discoveries from my explorations into new tech territories, particularly back-end development and cloud services. As I continue to broaden my tech understanding, I hope this series inspires and contributes to your own learning journey. Understanding Monolithic Architecture Before we dive into MSA, let's first talk about Monolithic Architecture. In this architectural style, all software components of an application are interconnected and interdependent. This architecture is simple to develop, test, and deploy initially. However, as the application grows, the complexity increases, making it challenging to maintain and scale. One of the significant drawbacks of a Monolithic Architecture is the need to build and deploy the entire system, even for a minor function change. This can lead to longer development cycles and makes continuous deployment challenging. The Emer

Daily #10: Quick Dive into Nullability Annotations in Java and Android

Hello! Today, I am going to talk about Nullability Annotations in Java and Android. These annotations - @NotNull , @Nonnull , @NotEmpty , @NotBlank , and @Nullable - are valuable tools to help us avoid unexpected null and empty values leading to runtime errors. @NotNull and @Nonnull : These annotations are similar; they declare that a variable, parameter, or method return value should never be null. @NotNull is from JetBrains' annotations library and is widely used in Android and Java development. @Nonnull is from the JSR-305 annotations library. Remember, these annotations themselves do not enforce the non-null behavior at runtime; they're primarily used for compile-time checks by static analysis tools. Let's see them in action: // Here, the parameter should never be null. public void processString(@NotNull String str) { // processing of str } // The method should never return a null value. @NotNull public String provideString() { // provide a String }

Daily#9. A Quick Dive into Android's AIDL

 One of Android's hidden gems is AIDL - Android Interface Definition Language. It's a tool that facilitates communication between processes running in different applications, a concept known as IPC (Inter-Process Communication).  AIDL allows you to define the programming interface that both the client and service agree upon to communicate with each other using IPC. The beauty of AIDL is that it can handle method calls with complex data types across different processes seamlessly.  Creating an AIDL interface is similar to creating an interface in Java. However, only certain data types are supported, such as primitives, String, CharSequence, List, and Map. Here's a simple example of an AIDL file: // IMyAidlInterface.aidl package com.example; interface IMyAidlInterface { void basicTypes(int anInt, long aLong, boolean aBoolean, float aFloat, double aDouble, String aString); } Once you've defined your interface, the Android sys

Daily#8. Understanding Static Methods and Variables in Android Development

 In the world of Android development, the static keyword plays an essential role. Understanding how and when to use static methods and variables can greatly improve your Android development skills.  The static keyword in Java means that the method or variable is associated with the class, rather than instances of the class. This implies that you can access static methods and variables without creating an instance of the class. Static Variables Static variables are shared among all instances of a class. They're initialized only once, at the start of the execution. Here's an example: public class MyClass { static int sharedVar = 10; } In this example, sharedVar is a static variable. If you create two instances of MyClass and modify sharedVar, they'll both operate on the same sharedVar, not their own copies. Remember to use them carefully as they remain in memory for the lifetime of your application, which can potentially cause memory

Daily#7. Simplifying Android Code with Lambda Expressions

 Java 8 introduced Lambda expressions, a new language feature which allows us to write our code more concisely and readably. They can be particularly useful in Android development, where handling events often requires the use of anonymous inner classes.  What are Lambda Expressions? Lambda expressions are anonymous functions; they're a way to represent instances of functional interfaces in a concise manner. A functional interface is an interface with just one abstract method. Benefits of Using Lambda Expressions 1. Conciseness : Lambda expressions can make your code more compact by reducing boilerplate, particularly when dealing with anonymous inner classes. 2.Readability : With less boilerplate, your code becomes more focused on what you're trying to achieve, making it easier to read. Using Lambda Expressions in Android Lambda expressions can be particularly helpful in handling UI events, such as button clicks. Here's an example that

Daily#6. Understanding and Using NetworkCallback in Android

The NetworkCallback class plays a crucial role in handling network changes in Android. It allows apps to monitor the network's state and perform actions accordingly. It has different types such as DefaultNetworkCallback, Request type NetworkCallback and Listen type NetworkCallback. Default Network  In Android, the "default network" refers to the network that is currently being used for internet traffic. Most of the time, it is the network that your device is connected to for accessing the internet, either via Wi-Fi or mobile data.  The default network can change based on factors like network availability, signal strength, and user preferences. For instance, if you're connected to both Wi-Fi and mobile data, Android generally defaults to using Wi-Fi because it's typically faster and doesn't incur data charges. However, if the Wi-Fi signal becomes weak or disconnects, Android will automatically switch the default network to mobile data (if available) to maintain

Daily#5. Android's Message and Handler

 Android's Message and Handler classes are key components of its message passing framework. They're used to schedule and execute code at a future point in time, and on a specific thread.  A Message represents a command that can be dispatched for processing. A Handler allows you to send and process Message and Runnable objects associated with a thread's MessageQueue.   Here's a simple example of sending a Message from a background thread to the main thread: Handler handler = new Handler(Looper.getMainLooper()); Message message = handler.obtainMessage(); // Set what, arg1, arg2, or obj if needed handler.sendMessage(message); Remember: Always obtain a Message from a Handler instance. This ensures the Message is correctly associated with the Handler's Looper.

Daily#4. Android's Threading Model and Looper

 Android uses a single-threaded model for UI operations, meaning all UI updates must happen on the main thread. The Looper class plays a crucial role in this model.  Looper is a part of Android's message passing framework. It's designed to keep a thread alive and to process Messages and Runnable objects from a MessageQueue.  Here's how you can use a Looper in a background thread: class ExampleThread extends Thread { public Handler handler; public void run() { Looper.prepare(); handler = new Handler(); Looper.loop(); } } Remember: Don't perform long-running operations on the main thread to avoid UI freezing. Use a background thread with a Looper for such tasks!

Daily#3. Understanding Android's Intent

In Android, an Intent is a software mechanism for describing an operation to be performed. It's a fundamental concept that facilitates communication between components such as activities, services, and broadcast receivers. An Intent can be explicit, where you specify the component to start by name, or implicit, where you declare a general action to perform and the system finds an appropriate component for you. Here's a simple example of explicit intent: Intent intent = new Intent(this, TargetActivity.class); startActivity(intent); And an example of an implicit intent: Intent intent = new Intent(Intent.ACTION_VIEW, Uri.parse("http://www.example.com")); startActivity(intent); Remember: Always declare intent filters for your components in the manifest if you want them to respond to implicit intents!

Daily#2. Handling Network Connectivity Issues in Android Apps

 When developing an Android app, it's important to ensure your app can handle network connectivity issues, especially when switching between Wi-Fi and mobile data. Android provides APIs to monitor network connectivity and report issues to help you manage your app's behavior in different network situations. Register a `ConnectivityManager.NetworkCallback` to monitor network changes: private ConnectivityManager connectivityManager; private ConnectivityManager.NetworkCallback networkCallback; private void registerNetworkCallback(Context context) { connectivityManager = (ConnectivityManager) context.getSystemService(Context.CONNECTIVITY_SERVICE); networkCallback = new ConnectivityManager.NetworkCallback() { @Override public void onAvailable(Network network) { // Handle network connection established } @Override public void onCapabilitiesChanged(@NonNull Network network, @NonNull NetworkCapabili

Daily#1. Using BroadcastReceivers for Alarm Functionality in Android Apps

In Android app development, one common way to implement alarm functionality is to use BroadcastReceiver . This allows your app to receive intents that are broadcast by other apps or the system itself, and take appropriate action based on those intents. public class AlarmReceiver extends BroadcastReceiver { @Override public void onReceive(Context context, Intent intent) { // Your custom alarm action here } } To set an alarm, use the AlarmManager system service, and set the appropriate PendingIntent to broadcast your custom intent: private void setAlarm(long triggerAtMillis, Context context) { AlarmManager alarmManager = (AlarmManager) context.getSystemService(Context.ALARM_SERVICE); Intent intent = new Intent(context, AlarmReceiver.class); PendingIntent pendingIntent = PendingIntent.getBroadcast(context, 0, intent, 0); alarmManager.setExact(AlarmManager.RTC_WAKEUP, triggerAtMillis, pendingIntent); } Don't forget to register your BroadcastRec

My very first post

  Hope it lasts long  previous blog https://sincenwhile.tistory.com/