Friday, December 22, 2017

Welcome to Developine

Welcome to Developine: Developine provides free online tutorials on Android, iOS, Spring-Boot, Kotlin programming language, Restful web services and Web Development.

Thursday, October 26, 2017

Fix issues After updating to Android Studio 3.0

Now I have my own blog.

Hi guys yesterday I received Android Studio 3.0 update and I immediately decided to update my Android Studio from 2.3.1 to 3.0.
And I faced some issues and than fixed those after going through different stack overflow posts. so I decided to mention all issues which You also can face when You will updated to Android Studio 3.0.

Lets update and Restart (Android studio update available)

After this You will be prompted to update Gradle plugin and gradle version for Android. Lets updated Gradle also.’
Now Your gradle wrapper file will have this version of gradle.
Now gradle sync will fail (I am telling my scenario :) )
First of all remove buildToolsVersion
No need of it now.
Now you can face this issue

Android studio 3.0: Unable to resolve dependency for ‘:app@dexOptions/compileClasspath’: Could not resolve project :projectName

You will face this issue because buildTypes in app build.gradle file should match with module build.gradle file.

Lets resolve this issue.

This was my build types block in app gralde file
buildTypes {
    staging {
        buildConfigField 'String', 'HOST', '""'
        buildConfigField 'String', 'REGION_CODE', '"1"'
        debuggable true
        signingConfig signingConfigs.debug
    QA {
        buildConfigField 'String', 'HOST', '"com.amazo/"'
        buildConfigField 'String', 'REGION_CODE', '"92"'
        debuggable true
        signingConfig signingConfigs.debug
    notificationTest {
        buildConfigField 'String', 'HOST', '"http://a6a"'
        buildConfigField 'String', 'REGION_CODE', '"92"'
        debuggable true
        signingConfig signingConfigs.debug
and this was my project dependencies
compile project(':slideDateTimePicker')
compile project(':scatter')
Happy Coding :) … share this with other developers. Thank you for reading.

Thursday, August 24, 2017

Serialization deserialization data class in kotlin example

Now I have my own blog.

If you want to pass custom data object from one activity to another in kotlin and for that purpose you need to serialize and deserialize data class.
Declare your data class like this
data class Albums(var folderNames: String, var imagePath: String, var imgCount: Int, var isVideo: Boolean) : Serializable
This is how you pass serialized data from one activity to another in kotlin
intent.putExtra("image_url_data", imagesList as Serializable)
// imagesList variable is type ArrayList<Albums>
Now you want to receive this data class object in second activity and want to deserialize it. This is how you will do this.
var listOfImages = intent.extras.get("image_url_data") as ArrayList<Albums>

A new Blog Developine

Check out this Gallery Application written in Kotlin on playstore. soon I will open source it. stay tuned!
Gallery Android Application on Google play store written in kotlin programming language.
Back to topic :) I recommend you to use parcelable instead of serializable.
Keywords : Kotlin, Serialization, DeSerialization, data class, arraylist, custom object, activity, android example, tutorial, Gallery application android.

Friday, June 2, 2017

Android Splash Screen and start Activity in Kotlin

In this post you will learn how to start new activity using Intent and how to implement splash screen logic in android application using Kotlin.

Code Moved to below link.
I assume you have two kotlin activities declared in manifest and one of them is launcher activity(your splash screen) and you want to launch MainActivity using Intent in kotlin and you need to stop at SplashActivity for 2–3 Seconds
import android.os.Bundle

class MainActivity : AppCompatActivity() {

    override fun onCreate(savedInstanceState: Bundle?) {
import android.os.Bundle
import android.view.View
import android.view.WindowManager
import android.view.Window
import android.os.Handler
import android.content.Intent
import android.content.Context

class SplashActivity : AppCompatActivity() {

    internal var SPLASH_TIME_OUT = 2000

    override fun onCreate(savedInstanceState: Bundle?) {

        getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN, WindowManager.LayoutParams.FLAG_FULLSCREEN);
                }, SPLASH_TIME_OUT.toLong())


Thursday, January 26, 2017

Android Application best performance improvement tips

Recently I got chance to work on ongoing project. which means I had to continue working on code written by other developers. so I had to understand code so I can start working on my part.
After looking at code I realized that code is poorly written and it has several performance related issues in layout files and java classes. so I started making list of all issues I noticed in Code so I can share with other developers(already working on project) and we can improve our Android Application.
Some friends/colleagues asked me how you were able to identify so many issues in code so I though I will write an article on this.
Some points which I shared with other members in first code review.
  • Application shared preferences need to be singleton (Currently creating new objects every time in each class)
  • Fire base analytics need to be initialized once. (same as above)
  • supportsRtl was set to false in manifest file (They had to add support for Right to left layouts,But they added static files for each language. 1 file for English, 1 layout file for Arabic)
  • Use of inner classes for AsyncTask
  • No exception Handling
  • No run time checks with implicit Intents
  • Too many static Application objects.

You can study further why above mentioned points are bad practices/discouraged.
After above phase I noticed that some layouts are taking time while rendering even without any network call. surely performance issue agree ? Than I decided that I have to identify more issues in code and have to improve Application.
Than I started working on memory monitoring using:
  • Android studio memory profiling (Heap Dump)
  • Leak Canary
And identified activities which are leaking memory. and shared my findings with team members so they can also learn and not repeat these mistakes in future.
I am sure still there are many performance issues in Application, so I decided to take advantage of Lint.
Go to Toolbar in Android Studio and Under Analyze section click Inspect Code.
I am still looking for performance issues in our Application because I want to make it best Application. Still I have not started working on my part. fixing issues in code :)
Than I installed a plugin “Find Bugs-IDEA” in Android studio and analyzed code using Find Bugs. this is how its result looks like.
After fixing all of the above issues plus memory leaks. I am now confident that we have followed standards to some extent and our code is much optimized now.
Happy Coding :)
Please ignore Grammar and Punctuation mistakes. English is not my native language :)
Hammad Tariq
Android Developer

Thursday, January 19, 2017

Configure Git Remote Repository

As our company started using Git instead of SVN. and my Manager has asked me to help other developers who are left with Git Configuration on their development machines. so I though I should write a blog post and list steps involved.

Let suppose below are your credentials
Remote repository URL: /home/git/customers/xyz/xyzproject/android
Git User name: hammad.tariq
password: xyzpass

Now I assume you have GIT installed.

Step 1:
Go to your project source code folder right click and select Git Bash here
Git interface will be opened.

Step 2:
Now you have local repository(folder) and you need to clone it with remote repository.
(your local repository will be copy of remote repository, your code pulled from remote will be saved in local and code in local will be pushed to remote repository).

First Command 
git clone ssh://hammad.tariq@XX.XXX.XXX.XX/home/git/customers/xyz/xyzproject/android

-If you have entered valid information it will prompt you for password.
-If there is already code on that repository, another developer has pushed already. This command will pull that code and will save into your local repository.

This will be printed on console if everything fine.
Cloning into 'android'...

Step 3:
If there is no code in your local repository copy paste code into your local repository so you can push it into remote repository.

Second Command
git add -A

Third Command
git status

Fourth Command
git commit -a -m "First Commit version 1.0.1"

Fifth Command
git push origin master

Now it will start pushing code.

If you get errors like below:

1- Error
fatal: failed to write object
error: unpack failed: unpack-objects abnormal exit

Solution: Than you don't have write permission for specified repository.

2- Error
! [rejected]        master -> master (fetch first)
error: failed to push some refs to ''
hint: Updates were rejected because the remote contains work that you do
hint: not have locally. This is usually caused by another repository pushing
hint: to the same ref. You may want to first integrate the remote changes
hint: (e.g., 'git pull ...') before pushing again.

hint: See the 'Note about fast-forwards' in 'git push --help' for details.

Solution: You are doing "git push origin master", You need to run "git pull" first.

3- Error
remote: error: refusing to update checked out branch: refs/heads/master
remote: error: By default, updating the current branch in a non-bare repository
remote: error: is denied, because it will make the index and work tree inconsistent
remote: error: with what you pushed, and will require 'git reset --hard' to match
remote: error: the work tree to HEAD.
remote: error:
remote: error: You can set 'receive.denyCurrentBranch' configuration variable to
remote: error: 'ignore' or 'warn' in the remote repository to allow pushing into
remote: error: its current branch; however, this is not recommended unless you
remote: error: arranged to update its work tree to match what you pushed in some
remote: error: other way.
remote: error:
remote: error: To squelch this message and still keep the default behaviour, set

remote: error: 'receive.denyCurrentBranch' configuration variable to 'refuse'.

git config receive.denyCurrentBranch ignore
run this command and try to push code again
Note: You need to run this command from server. (Git IP)

Kotlin Android MVP Dagger 2 Retrofit Tutorial