Camposha
  • Android
    • Introduction
    • Components
    • Communication
    • DateTime
    • FileSystem
    • HTTP
    • Local Database
    • Permissions
    • Scheduler
    • System
    • Widgets
    • Threading
    • Animation and Motion
    • Hardware and Sensors
  • C#
  • Flutter
  • Java
  • Javascript
  • Python
Sunday, January 17, 2021
No Result
View All Result
  • Login
  • Register
Buy Projects
  • Android
    • Introduction
    • Components
    • Communication
    • DateTime
    • FileSystem
    • HTTP
    • Local Database
    • Permissions
    • Scheduler
    • System
    • Widgets
    • Threading
    • Animation and Motion
    • Hardware and Sensors
  • C#
  • Flutter
  • Java
  • Javascript
  • Python
No Result
View All Result
Camposha
No Result
View All Result
Home Android Android Components

Intent HowTo’s with Omega Intent Builder

Oclemy by Oclemy
2 months ago
in Android Components
A A
4k
VIEWS
Share on FacebookShare on Twitter

In this piece we want to look at how several intent operations can be done using a library known as Omega Intent Builder. These are common operations that we need in almost all the apps we create. Omega IntentBuilder abstracts these operations allowing us to perform them using only a minimal amount of code.

Installation

The first step is to install Omega Intent. It’s hosted in jitpack so we have to register jitpack as a repository in our project-level build.gradle file.

allprojects {
    repositories {
        ...
        maven { url 'https://jitpack.io' }
    }
}

This library should be installed depending on the language you plan to use.

For Java:

dependencies {
    implementation 'com.github.Omega-R.OmegaIntentBuilder:core:1.1.4'
    // For extras
    implementation 'com.github.Omega-R.OmegaIntentBuilder:annotations:1.1.4'
    annotationProcessor 'com.github.Omega-R.OmegaIntentBuilder:processor:1.1.4'
    
    // AndroidX
    implementation 'com.github.Omega-R.OmegaIntentBuilder:core:1.1.6'
    // For extras
    implementation 'com.github.Omega-R.OmegaIntentBuilder:annotations:1.1.6'
    annotationProcessor 'com.github.Omega-R.OmegaIntentBuilder:processor:1.1.6'
}

For Kotlin:

For Kotlin rather than the annotation processor you use kapt:

apply plugin: 'com.android.application'
apply plugin: 'kotlin-android'
apply plugin: 'kotlin-kapt'

kapt {
    generateStubs = true
}

android {
    ......
}    
    
dependencies {
    implementation 'com.github.Omega-R.OmegaIntentBuilder:core:1.1.4'
    // For extras
    implementation 'com.github.Omega-R.OmegaIntentBuilder:annotations:1.1.4'
    kapt 'com.github.Omega-R.OmegaIntentBuilder:processor:1.1.4'
    
    // AndroidX
    implementation 'com.github.Omega-R.OmegaIntentBuilder:core:1.1.5'
    // For extras
    implementation 'com.github.Omega-R.OmegaIntentBuilder:annotations:1.1.5'
    kapt 'com.github.Omega-R.OmegaIntentBuilder:processor:1.1.5'
}

Lets proceed.

1.Activity

(a). How to Open Another Activity

To open an activity without passing any data:

OmegaIntentBuilder.from(this)
                .activity(PhotoCaptureActivity.class)
                .startActivity();

(b). How to Pass Data to an activity

To pass some extras:

OmegaIntentBuilder.from(this)
                .activity(PhotoCaptureActivity.class)
                .putExtra("Your_key", Integer.MAX_VALUE)
                .putExtra("Your_key2", Integer.MIN_VALUE)
                .startActivity();

To catch an exception while passing data:

       OmegaIntentBuilder.from(this)
                .activity(PhotoCaptureActivity.class)
                .putExtra("Your_key", Integer.MAX_VALUE)
                .putExtra("Your_key2", Integer.MIN_VALUE)
                .createIntentHandler()
                .failCallback(new FailCallback() {
                    @Override
                    public void onActivityStartError(@NotNull Exception exc) {
                        // you can handle error here
                    }
                })
                .failToast("Error")
                .startActivity();

 

(d). Activity Extras

Simple way to create and put data from one activity to another activity.

  • @OmegaActivity – annotation for activity.
  • @OmegaExtraModel – annotation for classes, which will be putted to bundle.
  • @OmegaExtra – annotation for fields, which will be putted to bundle.

@OmegaExtraModel and @OmegaExtra support prefix for generated method name.
If you wan’t annotate your class with @OmegaExtra – this class should be implements Serializable

First step – annotate your activity with @OmegaActivity

Second step – annotate fields with @OmegaExtraModel or @OmegaExtra

@OmegaActivity
public class ShareFilesActivity extends Activity {

    @OmegaExtra
    protected String url1;

    @OmegaExtraModel(prefix = "model")
    Model model = new Model();

    @OmegaExtra()
    Model modelTwo;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_share_files);
        AppOmegaIntentBuilder.inject(this);
    }
}

Third step – don’t forget write AppOmegaIntentBuilder.inject(this); in onCreate method.

Model class

public class Model implements Serializable {
    @OmegaExtra("Var2")
    String url;

    public String getUrl() {
        return url;
    }
}

Fourth step – fill out your data and start activity.

public class MainActivity extends Acitity {

AppOmegaIntentBuilder.from(context)
                .appActivities()
                .shareFilesActivity()
                .url1("https://developer.android.com/studio/images/hero_image_studio.png")
                .modelVar2("https://avatars1.githubusercontent.com/u/28600571?s=200&v=4")
                .startActivity();

}

Also you cant use @OmegaActivity just for start activity.

AppOmegaIntentBuilder.from(this)
                .appActivities()
                .shareFilesActivity()
                .startActivity();

(d). Fragment Extras Builder

Simple way to create and put data to fragment.

  • @OmegaFragment – annotation for fragments.
  • @OmegaExtraModel – annotation for classes, which will be putted to bundle.
  • @OmegaExtra – annotation for fields, which will be putted to bundle.

@OmegaExtraModel and @OmegaExtra support prefix for generated method name.
If you wan’t annotate your class with @OmegaExtra – this class should be implements Serializable

First step – annotate your fragment with @OmegaFragment

Second step – annotate fields with @OmegaExtraModel or @OmegaExtra

@OmegaFragment
public class FirstFragment extends BaseFragment {

    @OmegaExtra
    String value;
    
    @OmegaExtraModel
    Model model;

    public FirstFragment() {
    }

    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        AppOmegaFragmentBuilder.inject(this);
    }

Third step – don’t forget write AppOmegaFragmentBuilder.inject(this) in onCreate method.

Model class

public class Model implements Serializable {
    @OmegaExtra("Var2")
    String url;

    public String getUrl() {
        return url;
    }
}

Fourth step – fill out your data.

AppOmegaFragmentBuilder.secondFragment()
                       .value("Second fragment")
                       .createFragment();

 

Tags: Android Intent Examples
Share16Tweet10Send
Oclemy

Oclemy

When I was a 2nd year Software Engineering student, I buillt a now defunct online tool called Camposha(from Campus Share) using my then favorite language C#(ASP.NET) to compete OLX in my country(Kenya). The idea was to target campus students in Kenya. I got a few hundred signups but competing OLX proved too daunting. I decided to focus on my studies, learning other languages like Java,Python,Kotlin etc while meanwhile publishing tutorials at my YouTube Channel ProgrammingWizards TV which led to this site(camposha.info). Say hello or post me a suggestion: oclemmi@gmail.com . Follow me below; Github , and on my channel: ProgrammingWizards TV

Get Free Projects

Featured Projects

  • Become a Premium Member $30.00
  • CoronaVirus News App - Kotlin+MVVM+Firebase+Cloud Storage+Authentication+PageViews $12.00 $4.99
  • Largest Stars App - Kotlin+MySQL+MVVM+Retrofit2 Multipart+Data Binding+Disk Caching(2 Apps-Kotlin,Java) $12.00 $4.99
  • Alien Planets App - MVVM+Firebase+Cloud Storage(2 Apps-Kotlin,Java) $10.00 $4.99
  • Retrofit MySQL Multipart Images CRUD - UPLOAD DOWNLOAD UPDATE DELETE Full $10.00 $3.99

My Udemy Courses

Android MySQL Retrofit2 Multipart CRUD,Search,Pagination€19.99€14.99
Beginner Friendly Full Offline Android Apps Creation(Room)€19.99€14.99
Android Firebase MVVM Jetpack - Many Offline-First CRUD Apps€19.99€14.99
Kotlin Firebase CRUD,Cloud Storage,MVVM (Works even Offline)€19.99€14.99

Popular

  • Flutter PHP MySQL – Fill ListView with Images and Text

    45 shares
    Share 18 Tweet 11
  • Kotlin Android SQLite Simple CRUD – INSERT SELECT UPDATE DELETE

    45 shares
    Share 18 Tweet 11
  • Flutter SearchView Examples – ListView Search/Filter

    45 shares
    Share 18 Tweet 11
  • Kotlin Android Capture From Camera or Pick Image

    45 shares
    Share 18 Tweet 11
  • Android MySQL – Insert From EditText,CheckBox,Spinner – Part 4 [PHP Code]

    43 shares
    Share 17 Tweet 11
  • Trending
  • Comments
  • Latest

Flutter PHP MySQL – Fill ListView with Images and Text

December 19, 2020

Kotlin Android SQLite Simple CRUD – INSERT SELECT UPDATE DELETE

December 19, 2020
Flutter AppBar SearchView

Flutter SearchView Examples – ListView Search/Filter

December 19, 2020
Kotlin Android Capture From Camera or Pick Image

Kotlin Android Capture From Camera or Pick Image

December 19, 2020
CoronaVirus News App – Kotlin + MVVM + Firebase + Cloud Storage + Authentication+PageViews Count(Works even Offline)

CoronaVirus News App – Kotlin + MVVM + Firebase + Cloud Storage + Authentication+PageViews Count(Works even Offline)

10

Android Firebase RecyclerView MasterDetail CRUD Images Text – Upload, READ, DELETE

5

Android Retrofit – JSON ListView Images and Text

3

Framework7 Cordova – Compile App to APK and Install in Android Device/Emulator

3

Android Shared Element Transition Examples

December 27, 2020

Best Android Swipe Cards Libraries and Examples

December 27, 2020
Retrofit

Retrofit

December 19, 2020
Fast Networking Library

Fast Networking Library

December 19, 2020
  • Android
  • C#
  • Flutter
  • Java
  • Javascript
  • Python

Copyright © 2020 Camposha All Rights Reserved.

No Result
View All Result
  • Account
  • Activate
  • Activity
  • Become a Teacher
  • Become a Teacher
  • Become a Teacher
  • Become instructor
  • Blog
  • Blog
  • Cancel Payment
  • Cancel Payment
  • Cart
  • Change Password
  • Change Password
  • Checkout
  • Checkout
  • Checkout
  • Contact
  • Contact
  • Contact Us
  • Content restricted
  • Course Checkout
  • Dashboard
  • Edit Profile
  • Edit Profile
  • FAQs
  • Forgot Password
  • Forgot Password
  • Guest
  • Guest
  • Home
  • Home
  • Home Light
  • Instructor Dashboard
  • Instructor Registration
  • IUMP – Account Page
  • IUMP – Default Redirect Page
  • IUMP – Login
  • IUMP – LogOut
  • IUMP – Register
  • IUMP – Reset Password
  • IUMP – TOS Page
  • IUMP – Visitor Inside User Page
  • List courses
  • List wish list
  • Login
  • Login
  • Maintenance
  • Members
  • Membership Account
    • Membership Billing
    • Membership Cancel
    • Membership Checkout
    • Membership Confirmation
    • Membership Invoice
    • Membership Levels
  • Membership Account
    • Membership Billing
    • Membership Cancel
    • Membership Checkout
    • Membership Confirmation
    • Membership Invoice
    • Membership Levels
  • Membership Plans
  • My Account
  • OnePage Documentation
  • Portfolio Grid
  • Portfolio Masonry
  • Portfolio Multigrid
  • Privacy Policy
  • Products
  • Profile
  • Profile
  • Profile
  • Projects
  • Register
  • Register
  • Register
  • Register
  • Sample Page
  • Shop
  • Sign in
  • Sign up
  • Student profile
  • Student Registration
  • Thank You
  • Thank You

Copyright © 2020 Camposha All Rights Reserved.

Welcome Back!

Login to your account below

Forgotten Password? Sign Up

Create New Account!

Fill the forms below to register

All fields are required. Log In

Retrieve your password

Please enter your username or email address to reset your password.

Log In

Login

Forgot Password?

Create a new account

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.