Kicklabz

How could i run background services in android oreo




I faced the exact same problem working on a chat application so I know your pain. Our conclusion was:


you don't keep a connection alive 24/7, if you need to deliver a message to an user that has no connection alive, send a push message via Firebase.

If you want to keep a connection alive in background, you will face many problems. The first one, targeting Oreo, is that if your app is in background (definition of "background" in this context is here) it won't be allowed to run except for small time windows.

You can definitely use JobScheduler to run periodic tasks, they won't be executed at exact intervals or times to reduce battery usage (which is good) but it won't help you in keeping a connection alive. At best, you can use JobScheduler to periodically pull messages from you server. In order to use JobScheduler you need to create a JobService class.

JobIntentService is a new class introduced in API 26 of support library. It is a replacement for IntentService, it will run as a JobService on android API 26+ and as a Service (similar to IntentService in the sense that it will execute code in a background thread) on older APIs. On Oreo its background execution will still be limited so it won't help you in keeping a connection alive.

Using a foreground Service can really help you reducing the likelihood of the process being killed, but, you will need to display a permanent notification. It doesn't sound like a good solution for a chat app.

If you still think that having a 24/7 connection alive is a viable option, you need to consider also doze mode. You could ask the user to whitelist your app to run even in doze mode but you should have a very good reason to do that. Again, you would face the other bg execution limit in Oreo.

Another issue you will face is other apps. There are resources management apps that will aggressively kill other apps in bg to reduce memory and battery usage. For instance, I cursedthis one quite a bit.

Another issue is created by android. When the system is running low on memory, it will start killing processes of apps in bg. There is a an order in which they're killed, if I recall correctly should take into account last time it was in fg and current memory usage. Not the worst of the problems but still, it happens.

Then, if I still haven't convinced you in giving up the idea of the permanent connection, let me share with you yet another problem you would face. Some vendors implements extremely aggressivepolicies when it comes to killing bg processes, so that they're battery will last longer. For instance, Xiaomi.

Last tip, unrelated, but it took us a while to figure this out so I'm going to share it. If the user force stops your app from settings, your app is dead (that is, "stopped state") until the user actively launches it again, it won't even receive Firebase push messages.

Android studio keyboard shortcuts

Android studio keyboard shortcuts

Android Studio is the official integrated development environment (IDE) for Google's Android operating system, built based on JetBrains' IntelliJ IDEA software and designed specifically for Android development. It is available for download on Windows, macOS and Linux, and replaced the Eclipse Android Development Tools (ADT) as Google's primary IDE for native Android application development.

Here i am sharing some keyboard shortcuts that are very helpful during the development.

  1. Double tap shift - quick selection for all project files
  2. Ctrl + Alt + O - optimize and remove unused the imports from a class
  3. Ctrl + Alt + l - we can quickly format the code 
  4. Ctrl + D - Duplicates the line or selected portion of the code
  5. Shift + F6 - For renaming any elements within the project
  6. Left Alt + Enter - Auto filling dependencies
  7. Ctrl + / - Comment a line
  8. Ctrl + Left Alt + T - Surround selected code with try catch block , if condition etc..
  9. Left Alt + Insert - Adding implementations , constructors etc for the class
  10. Ctrl + F- Search anything within a file.
  11. Ctrl + Shift + F- Search in whole project.


Getting started with Android and Kotlin

Getting started with Android and Kotlin






This tutorial walks us through creating a simple Kotlin application for Android using Android Studio. 

Installing the Kotlin plugin

The Kotlin plugin is bundled with Android Studio starting from version 3.0. If you use an earlier version, you'll need to install the Kotlin plugin. Go to File | Settings | Plugins | Install JetBrains plugin… and then search for and install Kotlin. If you are looking at the "Welcome to Android Studio" screen, choose Configure | Plugins | Install JetBrains plugin… You'll need to restart the IDE after this completes.

Creating a project

It’s extremely easy to start using Kotlin for Android development. In this tutorial we’ll follow the warming up process with Android Studio. If using Intellij IDEA with Android, the process is almost the same.

First let's create a new project. Choose Start a new Android Studio project or File | New project. The following dialogs walk you through the process of new project creation. You need to name the project and choose which Android SDK version you have installed. Most options can be left with their default values, so you can press 'Enter' several times.

Name the project: Dialog 1

Android Studio 3.0 offers an option to enable Kotlin support on this screen. You can check this option and skip the "Configuring Kotlin in the project" step below.

Choose the Android version:

Dialog 2

Choose creating an activity that will be generated for you:

Dialog 3

Name the activity:

Dialog 4

In Android Studio 3.0, you can choose to create the activity in Kotlin right away, so you can skip the "Converting Java code to Kotlin" step. Earlier versions will create an activity in Java, and you can use the automated converter tool to convert it.

In general, the easiest way to start using Kotlin is to convert automatically Java activity into Kotlin one. Please note that anytime instead of looking through documentation for a new way to express an old pattern, you can write it in Java, then copy-paste Java code into Kotlin file, and IntelliJ IDEA (or Android Studio) will suggest to convert it.

Converting Java code to Kotlin

Open MainActivity.java file. Then invoke action Convert Java File to Kotlin File. You can do it by several ways. The easiest one is to invoke Find Action and start typing an action name (like in a screencast below). Alternatively you can call this option via the Code | Convert Java File to Kotlin File menu entry or by using the corresponding shortcut (you can find it at the menu entry).

Convert

After the conversion you should have an activity written in Kotlin.

Koltin-Activity

Configuring Kotlin in the project

If you start editing this file, Android Studio shows you a prompt that Kotlin is not configured, so you can configure it. Alternatively, you can invoke the configuration by selecting Tools | Kotlin | Configure Kotlin in Project from the main menu.

Config-Kotlin

You are then prompted for the version of Kotlin. Choose the latest available from the list of installed versions.

Config-Kotlin-Details

After you configure Kotlin, build.gradle file for the application should be updated. Now you can see that apply plugin: 'kotlin-android' and the kotlin-stdlib dependency were added.

(For more details how to set up gradle for your project, please check Using Gradle)

Sync-Project-With-Gradle

The last thing to do is to sync the project. You can press 'Sync Now' in a prompt or invoke an action Sync Project with Gradle Files.

Sync-Project-With-Gradle-2

Building and publishing the Kotlin application for Android

You are now ready to build the application and run it on an emulator or device. This works in exactly the same way as in Java. You can make a release of the application and sign it similarly to what you do for an Android application written in Java.

Kotlin has a rather small runtime file size: the library is approximately 859KB (as of 1.1.2-2). This means Kotlin adds just a little to .apk file size.

Kotlin compiler produces byte-code, thus there really is no difference in terms of look and feel of Kotlin applications versus those written in Java

Download Speed: 13 Ways to Increase Your Internet Speed Today

Download Speed: 13 Ways to Increase Your Internet Speed Today
download speed
Last Update February 28th, 2017
So you want to learn how to increase your download speed? Who wouldn’t?
Recently my area got upgraded to ADSL2+ and with it my speeds increased quite a lot. And you know what else increased? My productivity.
I was really surprised at how much the speed of my internet increased the amount of work I could get through; whether it was sending files, downloading and uploading images to blogs, or just loading new pages to read.
And more importantly, I was shocked at how much extra speed I could get through my line by tweaking a few things around my house.
In this post I am going to show you a few ways you can increase your internet speed. These are things you might not know about.
NOTE: This post contains affiliate links which means that I earn a small commission at no extra cost to you if you purchase a product after clicking from this article. Thanks for your support!

How to test your current internet speed

The first thing you will need to do is test your current internet speed. This will let you know whether or not you are getting a lower rate than you should be. You can do this by going to SpeedTest.net and running a test. Here are my results. Post yours in the comments below.
internet speed test
Now, this won’t be as fast as some people. A lot of European and American cities have super fast cable internet. And with Australia unveiling the world’s most expensive National Broadband Network, we should be getting speeds of up to 10GB per second. Yes, 10 GIG!
So, back to the point, I managed to speed up my internet to 11Mbps from around 6Mbps. It made a significant difference to me. I’ll show you how in a minute.
NOTE: If you want to test your speed in MBps then go here and go right click > save target as and observe the download or transfer rate.

What do MBps and Mbps mean and why does it matter?

Okay, so, some boring but important stuff here. People often say megabytes when they mean megaBITS. And visa versa. But there is a big difference.
MBps = megabytes
Mbps = megabits
So, if you refer to my speed test above you will see that I am getting 11.53 Mbps per second. To find out how many megabytes that is you just divide by 8 which equals 1.44 MBps.
Now, 1 MB is equal to 1024 KB (kilobytes) so if you want to know how fast you are going to able to download a song or movie you should refer to the KB or MB per second rate as that is usually what they are measured in.
For example, if you are downloading a 50 MB file at 1 MB per second it will take you just under 50 seconds. Got it?

Download faster: How to speed up your internet

Now let’s dive into a few ways that you can improve your internet speed. There are some things you will need to check before we try to speed things up.
  • What speed should you be getting?
    Internet companies often advertise huge speeds as a theoretical “potential” but in reality you will never get near it. Email or call your ISP and ask them what should really be getting.
  • How far away are you from the exchange?
    If you live a fair distance from the phone exchange then you won’t be able to reach maximum speeds. People who live closer to the exchanges get faster speeds every single time.
Once you know those things then we can move on towards getting your speed increased up towards it’s potential.
1. Test a different modem/router
The biggest cause of slowed down internet is a bad modem. For ages I was using a Billion modem that I thought was absolutely fantastic. I was having frequent internet drop outs and blaming them on my ISP. Finally I changed to a new NETGEAR N150 modem and speeds went up and the drop outs stopped. The problem? The old Billion modem wasn’t equipped for ADSL2+. Rookie mistake. Make sure your modem is suited to the internet plan that you are on.
netgear D6300
Update: I’m now using the above modem/router called the NETGEAR D6300 (AC1600 Dual Band Gigabit) which is lightning fast, has a huge wireless range and has many other cloud-based features. I highly recommend this bad boy.
2. Scan for viruses
The next thing you need to do is make sure that no virus itself is causing you to slow down. Sometimes viruses can live on your computer and suck resources away from what you are doing thus slowing down your speeds. I personally use this one as a daily scanner (aff link) on my PC and have found it to be the most accurate over time without slowing down my computer too much.
3. Check for on-system interference
Sometimes your virus scanner or other programs can interfere with your internet speeds. This is really frustrating but you can figure out by simply switching things off one at a time and then running a speed test again. Please note I won’t be responsible for any viruses or spyware you pick up whilst doing this. You should always have good virus protection.
4. Check your filters
If you have your internet connected to a phone line that also has a telephone on it then you will need to make sure you have good quality filters installed on your line. These are little plugs that you attach to the phone line and they help filter out the disturbances. Here is a photo of one of mine.
phone line filter
Now, these also need to be different for the different types of internet. If you have ADSL2+ or cable make sure you have the appropriate filter.
5. Try getting rid of your cordless phone
Some people disagree with this but I have found that cordless phones slow down or interfere with my internet even with filters. It is worth doing an isolation test by removing your phones and replacing them with different ones (borrow a friend’s) and see whether you get better results.
6. Plug in
Wifi is nice but wireless internet is often a tad slower than if you plug in to your modem. Try getting that chord out of the box and plugging straight into the modem, especially if it is your desktop computer and you don’t need to move it around very often.
7. Check for external interference
I bet most of you have an iPhone, iPad, sound system and at least one other form of electronic device in your modem area. Am I right? Well, if so, then you need to check to see whether these things are causing electromagnetic interference. Try moving speakers out of the way and getting other electronic devices out of your modem space.
8. Check for Foxtel or other types of TV
Old Foxtel boxes can cause interference for your internet, even if you aren’t using them. If your net speed is slower than it should be and you can’t figure out why, it might be an idea to go for a walk around your house and see if you have a Foxtel (cable TV) box that you didn’t know was there. It could be from a past owner. If so, call up and make sure it is disconnected totally.
9. Shorten and replace cables
The length of your cables and their structure can affect speeds. Try replacing old phone cables, sockets and lines and instead use shorter and newer ones. This can often make a big difference.
10. Have you tried turning it off and on again?
The last suggestion is often the most powerful one. Turn off your modem for one minute and turn it on again. It is called power cycling and can often flush out a bunch of problems that affect your speed. If you are really brave you can even reconfigure your modem with a new password as this can often refresh your settings at the end of your ISP and refresh connections.
11. Update firmware and software regularly
Your router/modem actually has it’s own software that you need to update regularly. You can login to your modem by following your brand’s instructions. For example, for a NETGEAR modem you go to http://routerlogin.com where you can update and tweak your settings. You also need to consider updating your computer’s desktop version, operating system, etc. as often the wireless settings become less compatible over time.
12. Find your router/ISP’s best settings
When you login to your modem/router (see point 11) you will see a bunch of settings relating to channels and so on. Sometimes these settings are not on the best option by default and you’ll need to update them based on the types of devices you use, etc. Check out your router and ISP’s website for the best settings.
13. Check the cabling and do a line test
If all of this fails it’s time to contact your Internet Service Provider and modem company and ask them for a line test and investigation. This may mean that a worker from the company will be sent out to your house, and this can cost an additional fee. The man who came to my property found that the wires in my roof were almost totally chewed away and needed replacing.

What have I missed?


Do you know any other ways to increase your internet speed? I would be really interested to hear them. If this post has helped you please consider giving it a little share on social media.

Android Version History

Android Version History

The version history of the Android mobile operating system began with the release of the Android alpha in November 5, 2007. The first commercial version, Android 1.0, was released in September 2008. Android is continually developed by Google and the Open Handset Alliance, and it has seen a number of updates to its base operating system since the initial release.
Versions 1.0 and 1.1 were not released under specific code names. Android code names are confectionery-themed and have been in alphabetical order since 2009's Android 1.5 Cupcake, with the most recent major version being Android 7.0 Nougat, released in August 2016.[1]


Code nameVersion numberInitial release dateAPI levelSupport status[2]
(No codename)1.0September 23, 20081Unsupported
(Internally known as "Petit Four")1.1February 9, 20092Unsupported
Cupcake1.5April 27, 20093Unsupported
Donut1.6September 15, 20094Unsupported
Eclair2.0–2.1October 26, 20095–7Unsupported
Froyo2.2–2.2.3May 20, 20108Unsupported
Gingerbread2.3–2.3.7December 6, 20109–10Unsupported
Honeycomb3.0–3.2.6February 22, 201111–13Unsupported
Ice Cream Sandwich4.0–4.0.4October 18, 201114–15Unsupported
Jelly Bean[10]4.1–4.3.1July 9, 201216–18Unsupported
KitKat4.4–4.4.4October 31, 201319Supported;[12] See clarification
Lollipop5.0–5.1.1November 12, 201421–22Supported
Marshmallow6.0–6.0.1October 5, 201523Supported
Nougat[7.0–7.1.2August 22, 201624–25Supported
O8.0TBA26Presupported
Courtesy - WikiPedia