Code Monkey home page Code Monkey logo

Comments (7)

StefMa avatar StefMa commented on May 24, 2024

from thirtyinch.

drmkraja avatar drmkraja commented on May 24, 2024

The Presenter is called once & the method listenChanges also called once. But the Listener onChildChanged is called repeatedly.
I too didn't though it was an Ti related Issue. But when i run the same code in an normal activity. The Listener works perfect!
Please take a look at my Fragment

public class MainFragment extends TiFragment<MyPresenter, MyView> implements MyView, MainAdapter.ClickListener {

    MainAdapter MyAdapter;
    GridLayoutManager layoutManager;

    @BindView(R.id.progress)
    ProgressBar mProgress;
    @BindView(R.id.list)
    RecyclerView mItemRecycler;

    @NonNull
    @Override
    public MyPresenter providePresenter() {
        return new MyPresenter(PrefUtils.getFromPrefs(getActivity(), "Email", null), MYConstants.FROM_MAIN;
    }

    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setRetainInstance(true);
    }

    @Override
    public View onCreateView(LayoutInflater inflater,
                             ViewGroup container,
                             Bundle savedInstanceState) {
        View fragmentView = inflater.inflate(R.layout.fragment_main, container, false);
        ButterKnife.bind(this, fragmentView);
        setupViews();
        return fragmentView;
    }

    private void setupViews() {
        layoutManager = new GridLayoutManager(getActivity(), 2);
        mItemRecycler.setLayoutManager(layoutManager);
        mItemRecycler.addItemDecoration(new GridSpacingItemDecoration(2, 15, false));
    }

    @Override
    public void showProgress() {
        mProgress.setVisibility(View.VISIBLE);
    }

    @Override
    public void hideProgress() {
        mProgress.setVisibility(View.GONE);
    }

    @Override
    public void showItems(List<Product> items, Map<String, String> cartItems) {
        MyAdapter = new MainAdapter(items, getActivity());
        MyAdapter.setCart(cartItems);
        MyAdapter.setClickListener(this);
        mItemRecycler.setAdapter(MyAdapter);
        mItemRecycler.setVisibility(View.VISIBLE);
    }

    @Override
    public void onProductAdd(Product item, int position) {
            getPresenter().listenChanges(item, 1, position);
    }

    @Override
    public void onProductRemove(Product item, int position) {
        getPresenter().listenChanges(item, 0, position);
    }

    @Override
    public void onItemQuantity(Product item, float quantity, int position) {
        getPresenter().listenChanges(item, quantity, position);
    }

    @Override
    public void refreshItem(Map<String, String> cartItems, int pos) {
        Log.e("NOTIFIED >> ", pos);
        MyAdapter.setCart(cartItems);
        MyAdapter.notifyItemChanged(pos);
    }
}

from thirtyinch.

passsy avatar passsy commented on May 24, 2024

You never unregister from your database. You receive calls until the presenter gets garbage collected. Unregister in onDetachView() when you register in onAttachView(view).

You're using a fragment. You may have run into a already existing bug #33 when you put the fragment into the backstack.

From the current description I cannot give help. "But it is getting called forever." is not very helpful. In which state is the presenter and win which state is the Fragment/Activity?
Please also provide a log using TiLog

from thirtyinch.

drmkraja avatar drmkraja commented on May 24, 2024

As per your advice, I'm removing the Listener from the database. The Listener only stops when the onDestroy method is called.
But it is getting called continously until I Press the back button.

LOG while Navigating from MainFragment to CartActivity

01-30 14:16:19.552 2188-2188/me.raja.medical D/MainFragment: Fragment onCreate
01-30 14:16:19.834 2188-2188/me.raja.medical D/MainFragment: onCreateView
01-30 14:16:20.084 2188-2188/me.raja.medical D/MyPresenter: PRESENTER IS CALLED
01-30 14:16:20.115 2188-2188/me.raja.medical V/ThirtyInch: MyPresenter:TiPresenter@9369474: deprecated onWakeUp()
01-30 14:16:27.572 2188-2188/me.raja.medical D/MyPresenter: LISTENER IS CALLED
01-30 14:16:27.607 2188-2188/me.raja.medical D/MyPresenter: onChildAdded > c01p01
01-30 14:16:27.607 2188-2188/me.raja.medical D/MyPresenter: onChildAdded > c02p01
01-30 14:16:27.608 2188-2188/me.raja.medical D/MyPresenter: onChildAdded > c02p02
01-30 14:16:27.608 2188-2188/me.raja.medical D/MyPresenter: onChildAdded > c02p03
01-30 14:16:27.609 2188-2188/me.raja.medical D/MyPresenter: onChildAdded > c02p04
01-30 14:16:27.634 2188-2188/me.raja.medical D/MyPresenter: onChildChanged > c02p02
01-30 14:16:27.634 2188-2188/me.raja.medical D/MyPresenter: onChildChanged > c02p02
01-30 14:16:28.231 2188-2188/me.raja.medical D/MyPresenter: onChildChanged > c02p02
01-30 14:16:28.885 2188-2188/me.raja.medical D/MyPresenter: onChildChanged > c02p02
01-30 14:16:28.886 2188-2188/me.raja.medical D/MyPresenter: onChildChanged > c02p02
01-30 14:16:29.511 2188-2188/me.raja.medical D/MyPresenter: onChildChanged > c02p02
01-30 14:16:29.511 2188-2188/me.raja.medical D/MyPresenter: onChildChanged > c02p02
01-30 14:16:29.522 2188-2188/me.raja.medical D/MyPresenter: onChildChanged > c02p02
01-30 14:16:29.523 2188-2188/me.raja.medical D/MyPresenter: onChildChanged > c02p02
01-30 14:16:29.956 2188-2213/me.raja.medical W/DynamiteModule: Local module descriptor class for com.google.firebase.auth not found.
01-30 14:16:31.443 2188-2188/me.raja.medical D/MyPresenter: onChildChanged > c02p02
01-30 14:16:31.443 2188-2188/me.raja.medical D/MyPresenter: onChildChanged > c02p02
01-30 14:16:31.460 2188-2188/me.raja.medical D/MyPresenter: onChildChanged > c02p02
01-30 14:16:32.062 2188-2188/me.raja.medical D/MyPresenter: onChildChanged > c02p02
01-30 14:16:32.712 2188-2188/me.raja.medical D/MyPresenter: onChildChanged > c02p02
01-30 14:16:32.713 2188-2188/me.raja.medical D/MyPresenter: onChildChanged > c02p02
01-30 14:16:32.724 2188-2188/me.raja.medical D/MyPresenter: onChildChanged > c02p02
01-30 14:16:32.724 2188-2188/me.raja.medical D/MyPresenter: onChildChanged > c02p02
01-30 14:16:32.832 2188-2188/me.raja.medical I/Timeline: Timeline: Activity_launch_request id:me.raja.medical time:144829152
01-30 14:16:32.895 2188-2219/me.raja.medical I/FA: Tag Manager is not found and thus will not be used
01-30 14:16:33.063 2188-2188/me.raja.medical V/ThirtyInch: TiActivityPlugin:TiActivity@2176b07f:CartActivity@2a8a084c: could not recover a Presenter from getLastNonConfigurationInstance()
01-30 14:16:33.072 2188-2188/me.raja.medical V/ThirtyInch: TiActivityPlugin:TiActivity@2176b07f:CartActivity@2a8a084c: created Presenter: CartPresenter:TiPresenter@2214e095{view = null}
01-30 14:16:33.072 2188-2188/me.raja.medical V/ThirtyInch: PresenterSavior: safe presenter with id CartPresenter:571793557:144829393159184 CartPresenter:TiPresenter@2214e095{view = null}
01-30 14:16:33.073 2188-2188/me.raja.medical V/ThirtyInch: CartPresenter:TiPresenter@2214e095: onCreate()
01-30 14:16:33.270 2188-2188/me.raja.medical E/RecyclerView: No adapter attached; skipping layout
01-30 14:16:33.335 2188-2188/me.raja.medical V/ThirtyInch: CallOnMainThreadInterceptor: wrapping View me.raja.medical.cart.CartActivity@2a8a084c in me.raja.medical.cart.CartActivity@2a8a084c
01-30 14:16:33.335 2188-2188/me.raja.medical V/ThirtyInch: DistinctUntilChangedInterceptor: wrapping View me.raja.medical.cart.CartActivity@2a8a084c in me.raja.medical.cart.CartActivity@2a8a084c
01-30 14:16:33.335 2188-2188/me.raja.medical V/ThirtyInch: TiActivityPlugin:TiActivity@2176b07f:CartActivity@2a8a084c: binding NEW view to Presenter me.raja.medical.cart.CartActivity@2a8a084c
01-30 14:16:33.335 2188-2188/me.raja.medical V/ThirtyInch: CartPresenter:TiPresenter@2214e095: onAttachView(TiView)
01-30 14:16:33.353 2188-2188/me.raja.medical D/CartPresenter: Cart Email >raja@gmail,com
01-30 14:16:33.359 2188-2188/me.raja.medical V/ThirtyInch: CartPresenter:TiPresenter@2214e095: deprecated onWakeUp()
01-30 14:16:33.383 2188-2188/me.raja.medical D/MyPresenter: onChildChanged > c02p02
01-30 14:16:33.383 2188-2188/me.raja.medical D/MyPresenter: onChildChanged > c02p02
01-30 14:16:33.386 2188-2188/me.raja.medical D/CartPresenter: Cart Items >c01p01
01-30 14:16:33.388 2188-2188/me.raja.medical D/CartPresenter: Cart Items >c02p23
01-30 14:16:33.389 2188-2188/me.raja.medical D/CartPresenter: Cart Items >c02p27
01-30 14:16:33.389 2188-2188/me.raja.medical D/CartPresenter: Cart Items >c02p28
01-30 14:16:33.404 2188-2188/me.raja.medical D/MyPresenter: onChildChanged > c02p02
01-30 14:16:33.405 2188-2188/me.raja.medical D/MyPresenter: onChildChanged > c02p02
01-30 14:16:33.427 2188-2188/me.raja.medical I/Timeline: Timeline: Activity_idle id: android.os.BinderProxy@39703d7b time:144829747
01-30 14:16:33.807 2188-2188/me.raja.medical V/ThirtyInch: MyPresenter:TiPresenter@9369474: deprecated onSleep()
01-30 14:16:33.807 2188-2188/me.raja.medical V/ThirtyInch: MyPresenter:TiPresenter@9369474: onDetachView()
01-30 14:16:33.808 2188-2188/me.raja.medical D/MainFragment: onDestroy
01-30 14:16:34.022 2188-2188/me.raja.medical D/CartPresenter: gold winner vanaspathi
01-30 14:16:34.951 2188-2188/me.raja.medical D/MyPresenter: onChildChanged > c02p02
01-30 14:17:51.510 2188-2204/me.raja.medical I/art: Debugger is no longer active

LOG when Back button is pressed from CartActivity

01-30 14:17:51.510 2188-2204/me.raja.medical I/art: Debugger is no longer active
01-30 14:22:13.197 2188-2188/me.raja.medical V/ThirtyInch: MainFragment:TiFragment@30ccf386: binding the cached view to Presenter DistinctUntilChangedProxy@3b6c15a3-MainFragment@30ccf386{presenter=MyPresenter@9369474}
01-30 14:22:13.198 2188-2188/me.raja.medical V/ThirtyInch: MyPresenter:TiPresenter@9369474: onAttachView(TiView)
01-30 14:22:13.198 2188-2188/me.raja.medical D/MyPresenter: PRESENTER IS CALLED
01-30 14:22:13.226 2188-2188/me.raja.medical V/ThirtyInch: MyPresenter:TiPresenter@9369474: deprecated onWakeUp()
01-30 14:22:13.430 2188-2188/me.raja.medical D/MyPresenter: onChildRemoved > c01p01
01-30 14:22:13.431 2188-2188/me.raja.medical D/MyPresenter: onChildRemoved > c02p01
01-30 14:22:13.432 2188-2188/me.raja.medical D/MyPresenter: onChildRemoved > c02p27
01-30 14:22:13.432 2188-2188/me.raja.medical D/MyPresenter: onChildRemoved > c02p28
01-30 14:22:13.446 2188-2188/me.raja.medical I/Timeline: Timeline: Activity_idle id: android.os.BinderProxy@2f1a0628 time:145169766
01-30 14:22:13.572 2188-2188/me.raja.medical V/ThirtyInch: CartPresenter:TiPresenter@2214e095: deprecated onSleep()
01-30 14:22:13.572 2188-2188/me.raja.medical V/ThirtyInch: CartPresenter:TiPresenter@2214e095: onDetachView()
01-30 14:22:13.602 2188-2188/me.raja.medical V/ThirtyInch: TiActivityPlugin:TiActivity@2176b07f:CartActivity@2a8a084c: Activity is finishing, destroying presenter CartPresenter:TiPresenter@2214e095{view = null}
01-30 14:22:13.602 2188-2188/me.raja.medical V/ThirtyInch: CartPresenter:TiPresenter@2214e095: onDestroy()
01-30 14:22:13.662 2188-2267/me.raja.medical W/RepoOperation: setValue at /S01/Customers/raja@gmail,com failed: DatabaseError: Permission denied
01-30 14:22:13.671 2188-2188/me.raja.medical D/MyPresenter: onChildAdded > c01p01
01-30 14:22:13.671 2188-2188/me.raja.medical D/MyPresenter: onChildAdded > c02p01
01-30 14:22:13.674 2188-2188/me.raja.medical D/MyPresenter: onChildAdded > c02p27
01-30 14:22:13.674 2188-2188/me.raja.medical D/MyPresenter: onChildAdded > c02p28
01-30 14:22:13.704 2188-2209/me.raja.medical I/art: Background partial concurrent mark sweep GC freed 34779(1655KB) AllocSpace objects, 3(52KB) LOS objects, 18% free, 36MB/44MB, paused 2.070ms total 123.051ms

LOG when Back button is pressed from MainFragment

01-30 14:26:21.794 2188-2188/me.raja.medical D/MyPresenter: onChildChanged > c02p02
01-30 14:26:21.801 2188-2188/me.raja.medical D/MyPresenter: onChildChanged > c02p02
01-30 14:26:21.802 2188-2188/me.raja.medical D/MyPresenter: onChildChanged > c02p02
01-30 14:26:21.802 2188-2188/me.raja.medical D/MyPresenter: onChildChanged > c02p02
01-30 14:26:22.006 2188-2188/me.raja.medical V/ThirtyInch: MyPresenter:TiPresenter@9369474: deprecated onSleep()
01-30 14:26:22.006 2188-2188/me.raja.medical V/ThirtyInch: MyPresenter:TiPresenter@9369474: onDetachView()
01-30 14:26:22.011 2188-2188/me.raja.medical D/MainFragment: onDestroy
01-30 14:26:22.012 2188-2188/me.raja.medical V/ThirtyInch: MyPresenter:TiPresenter@9369474: not calling onDetachView(), not woken up
01-30 14:26:22.014 2188-2188/me.raja.medical V/ThirtyInch: MainFragment:TiFragment@30ccf386: Activity is finishing, destroying presenter MyPresenter:TiPresenter@9369474{view = null}
01-30 14:26:22.014 2188-2188/me.raja.medical V/ThirtyInch: MyPresenter:TiPresenter@9369474: onDestroy()
01-30 14:26:22.016 2188-2188/me.raja.medical D/MainFragment: onDestroy
01-30 14:26:22.017 2188-2188/me.raja.medical D/MainFragment: onDestroy
01-30 14:26:22.467 2188-2188/me.raja.medical D/MyPresenter: onChildChanged > c02p02
01-30 14:26:22.467 2188-2188/me.raja.medical D/MyPresenter: onChildChanged > c02p02

from thirtyinch.

passsy avatar passsy commented on May 24, 2024

To be clear, your problem is that the you still receive callbacks in you MyPresenter attached to your MainFragment when the CartActivity is open?

Are you unregistering your callback in MyPresenter#onDetachView? Because this method is called correctly. If you correctly set the listener to null in MyPresenter#onDetachView you most likely have a problem in you listener implementation in you database. You sill keep the reference somewhere although it should be cleared.

What are you doning in MainFragment#onDestroy or onDestroy of you Activity? This seems to stop the data stream.

from thirtyinch.

drmkraja avatar drmkraja commented on May 24, 2024

I'm unregistering the callbacks in MyPresenter. The Listener is also removed when I press the back button or navigate to another activity.

    @Override
    protected void onDetachView() {
        super.onDetachView();
        myRef.removeEventListener(myListener);
    } 

The problem is that when i add the same listener in my TestActivity. The Listener prints only twice

D: onChildChanged > c02p01
D: onChildChanged > c02p01

But when I add the same Listener to MyPresenter. The Listener prints continously until onDestroy is called. Why it is happening. It should be called only twice as like the TestActivity ?

D: onChildChanged > c02p01
D: onChildChanged > c02p01
D: onChildChanged > c02p01
D: onChildChanged > c02p01
D: onChildChanged > c02p01
D: onChildChanged > c02p01
D: onChildChanged > c02p01
D: onChildChanged > c02p01
D: onChildChanged > c02p01
D: onChildChanged > c02p01
D: onChildChanged > c02p01
D: onChildChanged > c02p01
D: onChildChanged > c02p01
D: onChildChanged > c02p01
D: onChildChanged > c02p01
D: onChildChanged > c02p01

from thirtyinch.

passsy avatar passsy commented on May 24, 2024

Seems not Ti related.

Please debug you code, look where those calls come from, there is nothing we can help you here. Try stackoverflow for additional help.

from thirtyinch.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.