How to open our project/module activity from Applozic module?

Snehil Chouhan Source

I am using Applozic to integrate Chat in my app.

I have done all process and chat is working fine,

As I am doing customizations, I need to get back to my app's activity from applozic module class/activity.

When I write intent code, it shows my app should added as module inside applozic, but I have already added applozic to my app. It will become circular if I add again, although I have tried adding but still it is not working,

Please let me know, How to open our project/module activity from Applozic module?

Thanks

javaandroidfirebaseapplozic

Answers

answered 6 months ago Ashish Kanswal #1

You can open your Activity from applozic's ui module using the following ways:

1) Launch the activity directly using its name:

   try{
        String activityName = "YourActivityName";
        Class activityToOpen = Class.forName(activityName);
        Intent intent = new Intent(this, activityToOpen);
        startActivity(intent);
      }catch(ClassNotFoundException e){
   }

2) Create an interface in mobicomkitui's uilistener package with a call method:

package com.applozic.mobicomkit.uiwidgets.uilistener;

import android.content.Context;

public interface AlActionCallback {
    void onAction(Context context, String action, Object object); 
}

Call the interface method on press of a button or something, from where you want to launch the activity

onClick(){
  ((AlActionCallback) getActivity().getApplication()).onAction(getContext(), "startMyActivity", SomeObject);
}

Implement this interface in your Application class:

public class MyApplication extends MultiDexApplication implements AlActionCallback {

    @Override
    public void onCreate() {
        super.onCreate();
    }

    @Override
    public void onAction(Context context, String action, Object object) {
        if(action != null){
            switch (action){
                case "startMyActivity" :
                     SomeObject obj = (SomeObject) object;
                     Intent intent = new Intent(context, YourActivity.class);
                     intent.putExtra("someData",obj.getSomething());
                     startActivity(intent);
                     break;
            }
        }
    }
}

comments powered by Disqus