Retrolambda in Android
Hi, folks, it's been a long time since we have discussed with new changes happening in the Android world. Today I would like to convey about a new feature which is used in Java 8 called Lambda functions. It's very interesting that Java is improving its coding structure with new updations. Hence Java 8 was a previous year release and currently, they have updated with Java 9 we are eagerly updating our technological deeds soon. In this blog post, I would like to give some detail about Lambda functions which was introduced in Java 8. Lambda function helps in making the declaration and instance creation much more simple and faster execution process. It also helps in reducing the line of codes which lead a developer much easier and approachable access to the specific program he wrote. As we know from the latest Android Studio updates IntelliJ is automatically handling the methods and instance creation in converting to the lambda expression. But some more methods also can be handled by a programmer through Lambda expressions. Hence Android is currently supporting Java 7 which leads these new updates to make some difficulties in implementing in our Android project. Here I will suggest a method and a library which helps to pass Lambda expression in Android from my findings. The below link is a library called Retrolambda which can be used in Android project. https://plugins.gradle.org/plugin/me.tatarka.retrolambda. It gives a well-described method how to use it. Anyhow I will just pass the initial sample method here which can help a bit for beginners in using Lambda expressions in Android.
Retrolambda is a library which allows using Java 8 lambda expressions, method references and try-with-resources statements on Java 7, 6 or 5.
The Gradle Retrolambda Plug-in allows integrating Retrolambda into a Gradle-based build.
Adding Retrolambda to Gradle Build Configuration.
buildscript {
repositories {
jcenter()
}
dependencies {
classpath 'com.android.tools.build:gradle:1.4.0'
classpath 'me.tatarka:gradle-retrolambda:3.2.0'
// NOTE: Do not place your application dependencies
here; they belong
// in the individual module build.gradle files
}
}
Add the source and target compatibility to Java 8 and apply the new plug-in in yourapp/build.gradle
file.
apply plugin: 'com.android.application' apply plugin: 'me.tatarka.retrolambda' android { compileSdkVersion 22 buildToolsVersion "23.0.0 rc2" defaultConfig { applicationId "com.sample.android.retrolambda" minSdkVersion 22 targetSdkVersion 22 versionCode 1 versionName "1.0" } buildTypes { release { minifyEnabled false proguardFiles getDefaultProguardFile ('proguard-android.txt'),'proguard-rules.pro' } } compileOptions { sourceCompatibility JavaVersion.VERSION_1_8 targetCompatibility JavaVersion.VERSION_1_8 } } dependencies { compile fileTree(dir: 'libs', include: ['*.jar']) }
Using the lambda configuration by using it with your button to show a Toast once the button is clicked.
public class MainActivity extends Activity {
@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); Button view = (Button) findViewById(R.id.button); view.setOnClickListener(e-> Toast.makeText(this, "Hello World", Toast.LENGTH_LONG).show()); } }
Thanks for getting in touch
ReplyDeleteInfoligabola.org
Anekamasakan.web.id
Ligaindonesia.asia
Ligabolainggris.com
Absolutebsblog.net
I hope you're doing well
ReplyDeleteLigabolaspanyol.com
Chocolateblog.net
Serverpokeronline.net
Deusdoceu.com
Onenightymedia.com
I hope you enjoyed your weekend
ReplyDeleteListadicibo.web.id
Pkercollection.com
Fkossmpkotajakarta.web.id
Daftaranjingsetia.web.id
Agen Joker338
Hope this email finds you well
ReplyDeleteAgen Judi Bola Joker338
Bandar Judi Bola Joker338
Situs Serverbola Online
Sbobet Online
Taruhan Bola di Joker338
It's great to hear from you
ReplyDeleteAgen Sbobet terbaik
Agen Joker338 Terpercaya
Bandar Judi Bola Joker338
Situs Judi Bola Joker338
Agen Serverbola Terpercaya
It's great to hear from you
ReplyDeleteJudi Bola di Serverbola
Judi Bola di Joker338
Judi Bola di Agen Joker338
sbobet online
taruhan sbobet online
I hope you're having a great week
ReplyDeletesbobet
taruhan bola sbobet
agen sbobet bola
judi bola sbobet
judi bola sbobet online
Hope this email finds you well
ReplyDeleteBerita Liga Bola
Aneka Masakan
Liga Indonesia
Liga Bola Inggris
Judi Bola
I'm reaching out about...
ReplyDeleteLiga Spanyol
Chocolate Blog
Judi Online
Deposit Judi Online
Judi Bola
Thanks for the quick response
ReplyDeleteJenis Game Android
Judi Over Under
Wisata Kota Tua
Sejarah Anjing
Bandar Joker338
It's great to hear from you
ReplyDeleteSitus Judi Bola Joker338
Agen Judi Bola Joker338
Judi Bola di Serverbola
Sbobet
Judi Bola di Joker338
Agen Sbobet Terpercaya