You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I would like to ask how can I display bubble on the main thread in separated service (due to better code organization). I tried following, but when i started service using.
Intent myIntent = new Intent(mContext, BubbleService.class); mContext.startService(myIntent);
No bubble is displayed, without any exception.
Should i use the IntentService for this or how can i solve this issue?
Many thanks for any advice.
BubbleService:
public class BubbleService extends Service {
private Context mContext;
private BubblesManager bubblesManager;
private BubbleLayout currentBubbleLayout;
private Boolean isBubbleDisplayed = false;
private Handler mHandler;
private Runnable mRunnable;
public BubbleService() {
mContext = this;
}
@Override
public void onCreate() {
super.onCreate();
try {
Logger.d("onCreate");
showBubble();
} catch (Exception e) {
Logger.e(e.getMessage());
}
}
@Override
public void onDestroy() {
super.onDestroy();
//TODO: MOVE TO SEPARATED METHOD
//bubblesManager.recycle();
}
@Override
public IBinder onBind(Intent intent) {
return null;
}
private void showBubble() {
try {
Logger.d("Show bubble");
this.initBubble();
BubbleLayout mBubbleView = (BubbleLayout) LayoutInflater
.from(BubbleService.this).inflate(R.layout.bubble_layout, null);
//this.setTimerForInactiveBubble(mBubbleView); //TODO:UNCOMMENT AND RESET TIME WHEN USER TOUCHED THE BUBBLE
mBubbleView.setOnBubbleClickListener(mBubbleClickListener);
mBubbleView.setOnBubbleRemoveListener(mBubbleRemoveListener);
if(!isBubbleDisplayed) {
bubblesManager.addBubble(mBubbleView, 60, 20);
isBubbleDisplayed = true;
}
} catch (Exception e) {
Logger.e(e.getMessage());
}
}
private void setTimerForInactiveBubble(final BubbleLayout bubbleLayout) {
try {
Logger.d("setTimerForInactiveBubble");
mHandler = new Handler();
mRunnable = new Runnable() {
@Override
public void run() {
mBubbleRemoveListener.onBubbleRemoved(bubbleLayout);
}
};
mHandler.postDelayed(mRunnable,
Constants.Global.BUBBLE_DISMISS_DURATION);
mHandler.removeCallbacks(mRunnable);
} catch (Exception e) {
Logger.e(e.getMessage());
}
}
private BubbleLayout.OnBubbleRemoveListener mBubbleRemoveListener = new BubbleLayout.OnBubbleRemoveListener() {
@Override
public void onBubbleRemoved(BubbleLayout bubble) {
Logger.d("onBubbleRemoved");
bubble.removeAllViews();
isBubbleDisplayed = false;
}
};
private BubbleLayout.OnBubbleClickListener mBubbleClickListener = new BubbleLayout.OnBubbleClickListener() {
@Override
public void onBubbleClick(BubbleLayout bubble) {
try {
Logger.d("Clicked on the bubble");
if (CommonHelper.isDeviceOnline(mContext)) {
bubble.findViewById(R.id.avatar).setVisibility(View.GONE);
bubble.findViewById(R.id.loading_progress_bar).setVisibility(View.VISIBLE);
currentBubbleLayout = bubble;
}
else {
ToastHelper.showToastMessage(mContext, //TODO: ADD THE OFFLINE TRANSACTION //TODO: MOVE TOAST TO HELPER?
mContext.getResources().getString(R.string.no_internet_connectivity),
Constants.Global.DEBUG_ENABLED);
}
} catch (Exception e) {
Logger.d(e.getMessage());
}
}
};
private void initBubble() throws Exception {
Logger.d("initBubble");
bubblesManager = new BubblesManager.Builder(mContext)
.setTrashLayout(R.layout.bubble_trash_layout)
.build();
bubblesManager.initialize();
}
}
The text was updated successfully, but these errors were encountered:
This line makes that, when the service unbinds, it removes the bubbles. And it unbinds after completing the task for any IntentServices (e.g. instances of FirebaseMessagingService). Just add some logging to your onDestroy method. So the bubble is shown and automatically removed in the line above.
By commenting this line out, it worked for me from a remote device's notification.
Hello,
I would like to ask how can I display bubble on the main thread in separated service (due to better code organization). I tried following, but when i started service using.
Intent myIntent = new Intent(mContext, BubbleService.class); mContext.startService(myIntent);
No bubble is displayed, without any exception.
Should i use the IntentService for this or how can i solve this issue?
Many thanks for any advice.
BubbleService:
The text was updated successfully, but these errors were encountered: