Skip to main content

Posts

Showing posts from August, 2018

UI THREAD

In the UI Thread commands are executed line by line, meaning a command line is not executed until the current thread is finished executing. All of our application’s components ( Activities, Services, ContentProviders, BroadcastReceivers , etc.) are created within this thread, and any system calls made to those components are performed there as well. However, that doesn’t mean that all the huge processes must be executed in the main thread. There’s a workaround for this that can improve your app’s performance and give users a much better experience:  background threads . These threads are designed to handle any potentially long tasks that may hang your application. Typical examples of such tasks are network operations, which can involve unpredictable delays.

Current Location In Android

Steps to get location in Android Provide permissions in manifest file for receiving location update Create LocationManager instance as reference to the location service Request location from LocationManager Receive location update from LocationListener on change of location Provide permissions for receiving location update To access current location information through location providers, we need to set permissions with  android manifest  file. <manifest ... > <uses-permission android:name = "android.permission.ACCESS_FINE_LOCATION" /> <uses-permission android:name = "android.permission. ACCESS_COARSE_LOCATION" /> <uses-permission android:name = "android.permission.INTERNET" /> </manifest> ACCESS_COARSE_LOCATION is used when we use network location provider for our Android app. But, ACCESS_FINE_LOCATION is providing permission for both providers. INTERNET permission is must for the use o...

Event Handling(continued)

Event Listeners Registration Event Registration is the process by which an Event Handler gets registered with an Event Listener so that the handler is called when the Event Listener fires the event. Though there are several tricky ways to register your event listener for any event, but I'm going to list down only top 3 ways, out of which you can use any of them based on the situation. Using an Anonymous Inner Class Activity class implements the Listener interface. Using Layout file activity_main.xml to specify event handler directly. Below section will provide you detailed examples on all the three scenarios − Touch Mode Users can interact with their devices by using hardware keys or buttons or touching the screen.Touching the screen puts the device into touch mode. The user can then interact with it by touching the on-screen virtual buttons, images, etc.You can check if the device is in touch mode by calling the View class’s isInTouchMode() method. Focus ...

Android - Event Handling

There are following three concepts related to Android Event Management − Event Listeners  − An event listener is an interface in the View class that contains a single callback method. These methods will be called by the Android framework when the View to which the listener has been registered is triggered by user interaction with the item in the UI. Event Listeners Registration  − Event Registration is the process by which an Event Handler gets registered with an Event Listener so that the handler is called when the Event Listener fires the event. Event Handlers  − When an event happens and we have registered an event listener for the event, the event listener calls the Event Handlers, which is the method that actually handles the event. Event Listeners & Event Handlers Event Handler Event Listener & Description onClick() OnClickListener() This is called when the user either clicks or touches or focuses upon any widget like button, text, im...

Android Progress Bar using Progress Dialog

Progress bars are used to show progress of a task. For example, when you are uploading or downloading something from the internet, it is better to show the progress of download/upload to the user. In android there is a class called ProgressDialog that allows you to create progress bar. In order to do this, you need to instantiate an object of this class. Its syntax is. ProgressDialog progress = new ProgressDialog(this); Now you can set some properties of this dialog. Such as, its style, its text etc. progress . setMessage ( "Downloading Music :) " ); progress . setProgressStyle ( ProgressDialog . STYLE_HORIZONTAL ); progress . setIndeterminate ( true ); Apart from these methods, there are other methods that are provided by the ProgressDialog class Sr. No Title & description 1 getMax() This method returns the maximum value of the progress. 2 incrementProgressBy(int diff) This method increments the progress bar by the difference of value passed as a...

Date Picker

In order to show DatePickerDialog , you have to pass the DatePickerDialog id to  showDialog(id_of_dialog)  method. Its syntax is given below − showDialog ( 999 ); On calling this  showDialog  method, another method called  onCreateDialog gets automatically called. So we have to override that method too. Its syntax is given below − @Override protected Dialog onCreateDialog ( int id ) { // TODO Auto-generated method stub if ( id == 999 ) { return new DatePickerDialog ( this , myDateListener , year , month , day ); } return null ; } In the last step, you have to register the DatePickerDialog listener and override its onDateSet method. This onDateSet method contains the updated day, month and year. Its syntax is given below − private DatePickerDialog . OnDateSetListener myDateListener = new DatePickerDialog . OnDateSetListener () { @Override public void onDateSet ( DatePicker arg0 , int arg1 , int ...

Permissions

To maintain security for the system and users, Android requires apps to request permission before the apps can use certain system data and features. Depending on how sensitive the area is, the system may grant the permission automatically, or it may ask the user to approve the request. if(Build.VERSION.SDK_VERSION>=23) { checkselfPermission(Manifest.Permission.READ_External_Storage) !=PackageManager.PERMISSION_GRANTED} {String[]S={Manifest.permission.READ_EXTErNAL_STORAGE}; else{ } }else onRequestPermissionResult(int ReqCode,String[]perm,int[]res){ if(res.length>0) { if(res[0]==package.Manager>permission_granted); } proceed()}; else{ }

Notifications

A notification is a message you display to the user outside of your apps normal UI. When you tell the system to issue a notification, it first appears as an icon in the notification area. To see the details of the notification, the user opens the notification drawer. Both the notification area and the notification drawer are system-controlled areas that the user can view at any time. Notification Compat.Builder b=new NotificationCompatBuilder(this); b.setContentTitle(“Title”); b.setContentText(“Messahe”); b.setSmallIcon( R.drawable.image ); Intent i=new Intent(this, Second.class ); PendingIntent pi=PendingIntent.getActivity(this,i,pendingIntent.Flag_Update_Current); b.setContentIntent(pi); b.setAutoCancel(true); Notification n=b.build(); NotificationManager m=(notificationManager)getSystem Service(Notification_Service); m.notify(2,n); } }); }