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.
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.
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.
gradle-4.1-all.zip
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
Gradle could not resolve project :linkedin-sdk
I'm using Androis Studio 3.0 Canary 4. In my project i have the Linkedin-sdk, and it works. I can use it. The only…stackoverflow.com
I'm using Androis Studio 3.0 Canary 4. In my project i have the Linkedin-sdk, and it works. I can use it. The only…stackoverflow.com
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', '"http://compute.amazonaws.com/"'
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.
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) startActivity(intent)
// 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!
Canal Pic - Beautiful Photo Gallery - Android Apps on Google Play
Replace your gallery with this super fast, smart, modern and free with no ads.play.google.com
Replace your gallery with this super fast, smart, modern and free with no ads.play.google.com
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.
http://developine.com
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
MainActivity.kt
import android.support.v7.app.AppCompatActivity import android.os.Bundle class MainActivity : AppCompatActivity() { override fun onCreate(savedInstanceState: Bundle?) { super.onCreate(savedInstanceState) setContentView(R.layout.activity_main) } }
SplashActivity.kt
import android.os.Bundle
import android.support.v7.app.AppCompatActivity
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?) {
super.onCreate(savedInstanceState)
requestWindowFeature(Window.FEATURE_NO_TITLE);
getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN, WindowManager.LayoutParams.FLAG_FULLSCREEN);
setContentView(R.layout.activity_splash)
Handler().postDelayed(
{
startActivity(Intent(this, MainActivity::class.java))
finish()
}, 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
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
GIT IP : XX.XXX.XXX.XX
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 'https://hammadtariq@bitbucket.org/hammadtariq/xyz.git'
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'.
Let suppose below are your credentials
GIT IP : XX.XXX.XXX.XX
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 'https://hammadtariq@bitbucket.org/hammadtariq/xyz.git'
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'.
Solution:
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)
Thursday, October 20, 2016
android notification action button listener
Hi In this post I will add example code for how to add actions in your local notification and than add their click listener.
e.g in image below where notification has two options confirm or cancel and you want to check if user has canceled or confirmed without launching application. Than follow this tutorial.
I will add separate listener for Notification click and separate for notification action button click.Step 1: Add method for creating push notification.private void sendNotification(String messageBody) { Intent intent = new Intent(this, SplashActivity.class); intent.putExtra("fromNotification", "book_ride"); intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP); Intent intentConfirm = new Intent(this, NotificationActionReceiver.class); intentConfirm.setAction("CONFIRM"); intentConfirm.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP); Intent intentCancel = new Intent(this, NotificationActionReceiver.class); intentCancel.setAction("CANCEL"); intentCancel.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP); //This Intent will be called when Notification will be clicked by user. PendingIntent pendingIntent = PendingIntent.getActivity(this, 0 /* Request code */, intent, PendingIntent.FLAG_ONE_SHOT); //This Intent will be called when Confirm button from notification will be //clicked by user. PendingIntent pendingIntentConfirm = PendingIntent.getBroadcast(this, 0, intentConfirm, PendingIntent.FLAG_CANCEL_CURRENT); //This Intent will be called when Cancel button from notification will be //clicked by user. PendingIntent pendingIntentCancel = PendingIntent.getBroadcast(this, 1, intentCancel, PendingIntent.FLAG_CANCEL_CURRENT); Uri defaultSoundUri = RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION); NotificationCompat.Builder notificationBuilder = new NotificationCompat.Builder(this) .setSmallIcon(R.drawable.logo_steer) .setContentTitle("Madaar Ride") .setContentText("" + messageBody) .setAutoCancel(true) .setSound(defaultSoundUri) .setContentIntent(pendingIntent); notificationBuilder.addAction(R.drawable.ic_check_black, "Confirm", pendingIntentConfirm); notificationBuilder.addAction(R.drawable.ic_clear_black, "Cancel", pendingIntentCancel); NotificationManager notificationManager = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE); notificationManager.notify(11111 /* ID of notification */, notificationBuilder.build()); }
Step 2: Now Declare BroadcastReceiver for handling action events in manifest file.<receiver android:name="NotificationActionReceiver"> <intent-filter> <action android:name="CONFIRM" /> <action android:name="CANCEL" /> </intent-filter> </receiver>
Step 3: Add code for BroadcastReceiver ClassAuthor:/** * Created by hammadtariq on 8/9/2016. */ public class NotificationActionReceiver extends BroadcastReceiver { @Override public void onReceive(Context context, Intent intent) { if (intent.getAction().equalsIgnoreCase("CONFIRM")) { Toast.makeText(context, "Booking your ride", Toast.LENGTH_SHORT).show(); } else if (intent.getAction().equalsIgnoreCase("CANCEL")) { NotificationManager notificationManager = (NotificationManager) context.getSystemService(Context.NOTIFICATION_SERVICE); notificationManager.cancel(11111); } } }
Hammad Tariq
Android Application Developer
Subscribe to:
Posts (Atom)
Kotlin Android MVP Dagger 2 Retrofit Tutorial
http://developine.com/building-android-mvp-app-in-kotlin-using-dagger-retrofit/
-
Hi In this post I will add example code for how to add actions in your local notification and than add their click listener. e.g in image...
-
Hello Guys, Now I have my own Blog Site . please visit Link for more Android and Kotlin Tutorials. In this example I will teach yo...
-
In this example I will show you how to get precise call state in Android programatically using java reflection API. Add this in Andro...