Posts

Simple Notification in Android

Image
Notifications are a way to provide information to your customer which displays as a pop up on the device. It helps you to keep in touch with your customer. I am going to create a simple notification without going deep because everything is available on Google. We must understand a few concepts before going further. Notification channel:  Assume you have developed an app for an online learning center where they teach Maths and English. Students can either learn Maths, English, or Both. we must send notification related to Maths to only students who have taken Maths. In this case, we can create channels for Maths, English, and both so triggered notification will be delivered to students who have taken that subject. Each Notification channel can have a different Notification sound and different behavior that you can change from the Notification setting page. I forgot to tell you that Google has introduced the Notification channel from Android 8.0 i.e API level 26. Now yo...

SetError method in EditText box

Image
Today we are going to implement set error method for edittext.It is useful for diaplaying message if  user enters something wrong or leave it blank. MainActivity,java package com.arjun.test; import android.os.Bundle; import android.app.Activity; import android.view.Menu; import android.view.View; import android.widget.Button; import android.widget.EditText; public class MainActivity extends Activity { EditText edtname; Button btncheck; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); edtname =(EditText)findViewById(R.id.edtName); btncheck = (Button)findViewById(R.id.btnCheck); btncheck.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View arg0) { // TODO Auto-generated method stub if(edtname.getText().length() ==0) { edtname.setError("Please fill name....

Installing app on memory card by default

Add following line in manifest file of your android app.Your app will install in memory card by default Add only this line: android:installLocation = "preferExternal" and permission <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/> eg- <?xml version="1.0" encoding="utf-8"?> <manifest xmlns:android="http://schemas.android.com/apk/res/android" package="com.arjun.Medic" android:versionCode="1" android:versionName="1.0" > <uses-sdk android:minSdkVersion="8" /> <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/> <application android:icon="@drawable/ic_launcher" android:label="@string/app_name" > <activity android:name=".MedicActivity" android:label="@string/app_name" ...

Parsing JSON String in Android

Suppose i store my JSON response in string response. String response = {     "name": "John Smith",     "age": 32,     "employed": true,     "address": {         "street": "701 First Ave.",         "city": "Sunnyvale, CA 95125",         "country": "United States"     },     "children": [         {             "name": "Richard",             "age": 7         },         {             "name": "Susan",             "age": 4         },         {             "name": "James",             "age": 3         }     ] } { = This sign respresent that i...

SD Card in Android Enulator

Creating Sd card in emulator is east task.Just Follow these steps: step 1:Open your Android Virtual device manager(AVD) step 2:select your emulator step 3:Edit your emulator step 4:must specified size of your SD card 1024MB. step 5:in hardware option click new set property add SD card support: yes(value) step 6:start your emulator, in eclipse window–>showview–>other->android–>file explorer step 7->In file explorer open mnt->sdcard and using pushfile button for insert your file and image step 8:DONE

AsyncTask in Android

In Android, Services are used to keep running the application in background..If You want to small task in background then what you will do ??. In that case you have to use AsyncTask.                      If your appication requires connection with server,loading and uploading data to server etc. In such cases,your appication becomes more complex.You can solve this by using AsyncTask.You can show a user some kind of notification or progressdialog box to display something on main screen while loading data from server in background without interuppting the main thread.                                 AsyncTask is an abstract class that provides several methods managing the interaction between the UI thread and the background thread. it’s implementation is by creating a sub class that extends AsyncTask and implementing the different protected me...

Difference between Handler and AsyncTask

The Handler is associated with the application’s main thread. it handles and schedules messages and runnables sent from background threads to the app main thread. AsyncTask provides a simple method to handle background threads in order to update the UI without blocking it by time consuming operations. exapmle:if you want to download something and while downloading you can show ProgressDialog to user without interupting the execution of main ui thread. Both can be used to update the ui from background thread. You may consider using handler it you want to post delayed messages or send messages to the MessageQueue in a specific order. You may consider using AsyncTask if you want to exchange parameters (thus updating UI) between the app main thread and background thread in an easy convinient way.

Handler in Android

Need to notify user when for example user clicks button and in onClick method program starts some long-time process. Need to have some solution which will do your task in background. Handler is very good solution for this problem. If you will not use such approach then user will see that program appears to hang.                                                  When you create an object from the Handler class, it processes Messages and Runnable objects associated with the current thread MessageQueue . the message queue holds the tasks to be executed in FIFO (First In First Out) mannser. you will need only ine Handler per activity where the background thread will communicate with to update the UI. The Handler is associated with the thread...