EventListener is small library and is used for communication between classes like broadcaste signals No Need to maintain listener reference. It auto work with app lifecycle.
- Android 14
allprojects {
repositories {
...
maven { url 'https://jitpack.io' }
}
}
dependencies {
implementation 'com.github.prabhat1707:EventListener:1.0'
}
EventListener.getInstance().post(modelClass, "From Fragment");
- if you want to rec your post modelclass as well as Tag in callback then pass ModelClass Type in DataWrapper
implement Updatable<DataWrapper<ObjectClass>> :
@Override
public void EventListenerCallback(DataWrappe<ModelClass> objectDataWrapper) {
Toast.makeText(this, objectDataWrapper.getTag(), Toast.LENGTH_SHORT).show();
text.setText(objectDataWrapper.getObject().getTest());
}
// objectDataWrapper.getObject return your modelClass
- default is
implements Updatable<DataWrapper>
@Override
public void EventListenerCallback(DataWrapper objectDataWrapper) {
Toast.makeText(this, objectDataWrapper.getTag(), Toast.LENGTH_SHORT).show();
}
- register or unregister the callback according to your logic for ex-:
@Override
protected void onResume() {
super.onResume();
EventListener.getInstance().registerListener(this);
}
@Override
protected void onDestroy() {
super.onDestroy();
EventListener.getInstance().unregisterListener(this);
}
-
EventListener.getInstance().post("From Fragment"); // only Tag
-
EventListener.getInstance().post(); // without Tag and data
-
EventListener.getInstance().post(modelClass, "From Fragment"); // with data also
Found a bug? Something that's missing? Feedback is an important part of improving the project, so please,
Thank You..
Copyright 2018 Prabhat Rai
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.