last day (18 days later) » 

11:21 AM
1
A: Setting variable through protected function - lost reference

SergGrUpdate What's going wrong? You use ViewPager in combination with FragmentPagerAdapter. What is an important implementation deatil of this combination is that you have several Fragments attached to the Activity. This is required for ViewPager to work as it need at least next and previous Fragme...

 
what you man add "Add this to each Log call"? I've already traced out String.valueOf(this.getClass()) in log calls and the result is shown in last quote - last call is from instance of different class so it's obviously not the same instance. :)
 
@PawełAudionysos, I was suggesting loggint this instead of this.getClass() so you could see somehting like you.package.A@1234#hashCode which would be more unique for different objects, but yes I was wrong and your updated log already says that the last line comes from different object. So me next idea would be to override registerForContextMenu in your class A and log there this, probably with stack trace using Thread.currentThread().getStackTrace() so then you can find out how C is registered there. P.S. you didn't answer if the issue is easily reproducible.
@PawełAudionysos, If the bug is reproducible and you are willing to share the code and provide clear steps to reproduce, someone will be willing to debug (most probably including me0
 
I believe the bug was persistent but the be honest I didn't compile it since then so I need to refresh my memory about this. I would be posting some updates today on this, trying to make question more clear and maybe I would post the code. Can yo tip me how I should post the project? It's many files and I'm generating those lists base on data from database. The code is quite generic. Easiest for me would be to post entire project but I don't want to frighten anyone with it's complexity. Also should I post it on github or pack it in archive? What you think?
 
@PawełAudionysos, it might be that all SO users will be frightened by your code but do you have any better alternatives now? As for putting it to the GitHub vs packing, it is mostly up to you. One thing is that I don't know whether putting it to GitHub automatically enforces it to become some sort open-source or not. Packing obviosly avoids this issue altogether. Also don't forget to provide clear "Steps to reproduce"!
@PawełAudionysos, I played with your code a bit and can't reproduce the issue. I pre-filled all tabs with some fake data. I assume that B is LocalizationsFrag and you have to do something with context menu there but it seems to work OK at the first glance. So steps to reproduce are welcome. Or do I have to change something in the code as well?
 
Thanks for your interest! Seriously I cannot tell you right now how to reproduce it. I probably did something as work around "for a moment" but I'm going to sleep already so if you are not very curious, just wait for more info, a should post it tomorrow.
 
11:21 AM
@PawełAudionysos, I think I've found the reason of your issues. See my updated answer. Also just in case I've uploaded my current copy of your project to dropmefiles.com/vlXuc Note that the link will expire in a week or two. Also note that besides fixes there is some code to populate your UI with fake data. It is mostly around populateFromLocal
 
Thank you. You found the root of the problem. You are grate and bounty comes to you. However as for your concerns. I understand that my code is kind of unusual and you don't use to such format but despite the fact were in some cases it's basically lack of my knowledge on java or android, many aspects of my design are are done on purpose. For example I like to see line like "setMenus(new String[]{"Call", "SMS", "Email", "New Order","Navigate to location"}, null);" at the top of my class.
Because even if you have no idea what the class suppose to do you can quickly recognize that this is responsible for the menu list you see in app, simply by reading this single line (these are actual strings you see). and than if I would like to have another language later I would simply add some line like Translator.fromCurrentDict(s); at the top of addItemMenu function.
"If at some point this becomes a limitation and you would like to create an action that is specific to sub subclass of BaseCustomFragment" That was actually main reason I wrote it that way - if I want to have custom menu item all I need to do is add string to setMenus (+0 lines) and add single if statement (+2 lines?) and if onContextItemSelected is not already overridden (+3 lines?). And that's it - in summary gives me about +5 new lines while in comparison in your example "you just have to create menu item in the corresponding sub-class." gives about +20 which is mostly boilerplate.
With all respect the thing you shown looks like using tank to kill a fly. I would even agree to create a class for menu item but extending each single item? Seems completely awkward to me but I understand this approach is imposed by events model. This is so strange and unpractical that events in java are implemented using interfaces...
As for question on why I use TimesStamp - I don't know, Obviously I don't need nanosecond, what should I use? I remember I was struggling with this for few hours as there is no single clear method how I should store this.
I'm not very experienced in Java. I spend on this project maybe 2-3 weeks so it's not so obvious as for someone who programs Java in daily basis. I even recently check something, didn't find it but instead I found some article about Minecraft (on oracle java programming site) NC...
Again I would rather prefer to stay with clear 12 lines which define behaviour of all basic menu options that 90 line which give no clear benefit for cost of not even fit on screen and introduce more confusion.
I mean come one! All we want to do is to display a list of few items to be clicked and define what act
 
 
9 hours later…
8:38 PM
I disagree with you about "clear 12 lines". Don't you forget duplicated logic to show/hide Call, SMS and E-mail menu items in different Fragments? The main benefit of my approach (besides that fact, that it actually works) is that all the relavant logic is in the single clear place quite unlike your code where I have to go through all the fragments to understand how each action works.
Just imagine what should you do with your approach, if you want to change business logic. For example, assume there might be two phone numbers for each customer: real "external" phone number and a short 4-digits internal number for PBX. And also assume that for each Customer there might be any of these two or both or none. How much code do you need to change? All my changes would be in 2 lines. I think you'll have two change much more.
And as for "setMenus(new String[]{"Call", "SMS", "Email", "New Order","Navigate to location"}, null);" in the base class, I didn't like this line at all because when I opened the app and tried to call context menu I've seen only two of those items. This line actually lied to me! I think that you like your code only because it was written by you so you remember your decision. For an outside developer the code is quite confusing.
And as for more code, any modern IDE such as Android Studio will generate stubs for you so you write only important parts and also even will collapse it so it will look short in the Editor.
 
 
3 hours later…
11:32 PM
"Don't you forget duplicated logic to show/hide Call, SMS and E-mail menu items in different Fragments?"

How you see that as duplicated logic? Notice that the only reason why you see "Call, SMS" in both CustomerFrag and OrdersFrag is that Order could have nested Customers bound to itself and You can call Customer even from Orders fragment in that case - It would be pretty overkill to implement something more generic just to handle that single exception. Now Look and LocalizationsFrag and tell me were you see "show/hide" logic in there? There is no. Why? Because it's custom data/fragment sp
 
11:59 PM
In your original arhice CustomerFrag.java lines 38-41 and OrdersFrag.java lines 41-45 aren't those 3 quite similar to 3 of 4 another lines? Can you find such duplication in my code?
 

  last day (18 days later) »