Posts

Showing posts from November, 2017

Right place to initialise Progress Dialogs

It is always easy to create a function in the Util class created which is being used in all other activities. But when progress dialog is created there is a little possibility that we might get an exception. BadTokenException This exception is mainly because the progress dialog is not initialise. So, to overcome this problem I will suggest a right place to initialise progress dialog. It should be initialised right above the code line where it is shown. void requestToServer(){        //Initialise progress dialog here        // show progress dialog here       onResponse(){              //dismiss progress dialog       } }

Passing Data from activity to fragment Android

While developing my application I came across a situation in which i had six fragments four on the same activity and two fragment on one fragment and each fragment is loading some data from the internet sending the Volley Request. It was creating there Volley Request in the same time. Ideally it should send only one. So, I wrote a code in which there is only one single request to server in the beginning. Next thing is to send the data in the form of list to the fragments. For that we have to go there where the object of the fragment is created and using that object we have to pass the data to the fragment in the form of arguments and arguments accept only Bundle, so we have to put our list in Bundle first. Important thing is that the bean or pojo of which our list is a type should be implementing Serializable. The code is like Bundle bundle= new Bundle(); FragmentTransaction fragmentTransactionHome=getSupportFragmentManager().beginTransaction(); UserHomeFragment userHomeFragme

Styling Bottom Navigation

Image
Styling Bottom Navigation Off the bat, the library provides considerable styling options. But after recent updates, there has been a lot more. Some of these additions include notification badges and coordinating behaviors. It also includes  on-scroll Quick Return pattern . Its all that one could ever want with the Bottom Navigation. This library is much more feature-rich than  what Android Design Support Library offers . So if you want more customization options and more control, you know what to use. Before we get to that, here’s a heads-up. We’ll be using and referencing a lot of colors. Normally, we reference colors in Android like this: ContextCompat.getColor(context, R.id.yourcolor); Now I’m no fan of writing such a lengthy line for fetching a simple color resource. So I’ll write a simple method that shortens what I have to type. private int fetchColor( @ColorRes int color) { return ContextCompat.getColor(this, color); } Great! From now on I don’t have

Creating Bottom Navigation in Android

Image
What is Bottom Navigation? Bottom navigation bars make it easy to explore and switch between top-level views in a single tap. —  Material Design spec This helps developers opt for Bottom Navigation, instead of a Navigation Drawer. If you have about four top-level navigation items, its ideal to use Bottom Navigation. Otherwise, go for a Navigation Drawer. We don’t want the Bottom Navigation looking too crowded now, do we? This was already common for iOS apps. But now, a lot of Android apps have started adapting this. To name a few, the YouTube app recently made the switch. YouTube app’s simplified navigation with Bottom Bar When to use? A Bottom Navigation is best used when you have three to five top-level navigation items of similar importance. Until now, the default, go-to navigation solution is the  Navigation Drawer . Would you agree? Grab all your screens, throw them in the Navigation Drawer and we’re done. I don’t blame you. Once upon a time, I was guilty o

Checking the version of application which I am currently using in my app.

Checking the version is because we have to make the users to update the application so that there is no error when we change the scripts from the server. Use: try { PackageInfo pInfo = this . getPackageManager (). getPackageInfo ( getPackageName (), 0 ); String version = pInfo . versionName ; } catch ( PackageManager . NameNotFoundException e ) { e . printStackTrace (); } And you can get the version code by using this int verCode = pInfo . versionCode ;

Shifting from normal PHP scripts to PDO Scripts.

PHP Scripts are used a lot but on changing the trend is the new PDO Scripts. Moreover shifting from normal servers to AWS server i.e Amazon Web Services then we have to use PDO scripts. There are a lot of new things to do in PDO Scripts but some main points are to be followed while converting them. Retrival - mysql_query is changed with $DBH->query()  where $DBH is the reference variable of the Object in PDO setFetchMode(FETCH_MODE::ASSOC); This mode is used for the retrieval of associative array Insertion and Updation-  For insertion and updation prepare statements are used. Statements are prepared using the command as shown. There is an array which is used for the creation of prepared statements. $array=array("Values"); $DBH->prepare("Prepare Statement");

What's the difference between commit() and apply() in Shared Preference

apply()  was added in 2.3, it commits  without  returning a boolean indicating success or failure. commit()   returns   true   if the save works,   false   otherwise. apply()  was added as the Android dev team noticed that almost no one took notice of the return value, so apply is faster as it is asynchronous commit()   writes the data   synchronously   (blocking the thread its called from). It then   informs  you about the success of the operation. apply()   schedules the data to be written   asynchronously . It   does not inform   you about the success of the operation. If you save with  apply()   and   immediately read   via any getX-method, the   new   value will be returned! If you called   apply()   at some point and it's still executing, any calls to   commit()   will block until all apply-calls and its own commit are finished.