Office Hours — Today, March 31

Thursday, March 28

Mark M.
has entered the room
Mark M.
turned on guest access
Anshul V.
has entered the room
Mark M.
hello, Anshul!
how can I help you today?
Anshul V.
Hi Mark, how's it going?
Mark M.
OK, and you?
Mar 31
4:00 PM
Anshul V.
Um, well! I am not sure how much you remember of the problem I was asking you about dynamically adding and deleting the viewpager fragments (user input forms). Here's the stackoverflow link https://stackoverflow.com/questions/54581480/an...
Mark M.
I vaguely remember this
Anshul V.
I fugured as much. The top level problem, if I may tell, is that everything is working perfectly, the dynamic addition of fragments in viewpager is working perfectly. The only issue now that I am facing is that, when I go to delete a fragment dynamically, especially if it is a middle fragment, the last fragment gets deleted, always!
so if I have 1, 2, 3 fragments in the viewpager, and I delete the 2nd fragment, I expect the viewpager after notifyDatasetChanged() to be 1,3. But instead of that, it is 1, 2
4:05 PM
Mark M.
I am not aware that FragmentPagerAdapter has notifyDataSetChanged()... hold on while I look this up
Anshul V.
Sure thing!
Mark M.
OK, I see it on PagerAdapter -- not sure why FragmentPagerAdapter's JavaDocs are not showing it
no, I am just short on sleep -- it is in FragmentPagerAdapter too
it is possible that FragmentPagerAdapter simply does not support this level of modification
I had problems with this sort of thing years ago
I wound up writing my own PagerAdapter to compensate
Anshul V.
Ahaha, yeah! And I am sure there is something wrong with the way I am deleting the fragment, because addition of fragment works perfectly..
Mark M.
well, bear in mind that while you are creating the fragments and managing your ArrayList, it is FragmentPagerAdapter that is responsible for the FragmentTransactions
in theory, notifyDataSetChanged() should cause FragmentPagerAdapter to remove all current fragments, then start over
but, there may be bugs in that logic
you might consider stepping into notifyDataSetChanged(), to get a sense of what FragmentPagerAdapter is doing when you call it
4:10 PM
alan
has entered the room
Anshul V.
That is true. I am just wondering what I can do to solve this problem, recently google released Viewpager2, which solves the notifyDatasetChanged() problem while has been there for a while, and that is when I realized that my code in deleteFragment() method is what is causing the problem
Mark M.
I have not looked at ViewPager2 at all yet, so I can't comment on it
but I would first focus on understanding what notifyDataSetChanged() does, so you know better how to compensate
let me take a question from Alan, and I will be back with you shortly
Alan: hi! how can I help you today?
Anshul V.
Sure thing!
alan
hi
I am using android studio 3.3.2. The project view's file display does not show all the files my hard disk shows. I've tried pressing the "sync folder with file system" button and it still does not show some files
4:15 PM
Mark M.
what is the selected optionin the drop-down at the top of the Project view? is it "Project", "Android", or something else?
alan
Android
Mark M.
change it to "Project" and see if you like the results better
alan
no :(
Mark M.
OK, what seems to be missing?
alan
files ending with "Injectors_Module"
I mean InjectorsModule sorry
Mark M.
I have no idea what such files are or why Android Studio might be filtering them out
alan
or more specifically InjectorsModule.kt
Mark M.
OK, so this is a Kotlin source file
alan
I recently tried excluding them from global file search by creating a custom scope. But I deleted the scope and it still fails to show up
yes it is a kotlin file
Mark M.
is it in your src/.../java tree like the rest of your Kotlin, or is it someplace else?
Anshul V.
Hey Mark, I will keep looking into understanding notifyDatasetChanged(). Thank you for all your help! Have a good day..
Mark M.
Anshul: you too!
Anshul V.
has left the room
4:20 PM
alan
it is. I can actually see other files in the same directory, just not the ones that match the ones I exclude via the regex " *_Factory.java;*.hprof;*.pyc;*.pyo;*.rbc;*.yarb;*InjectorsModule*;*_MembersInjector.java;*app_debugFactory*;*~;.DS_Store;.git;.hg;.svn;CVS;__pycache__;_svn;vssver.scc;vssver2.scc;"
Mark M.
you have been tailoring Android Studio much more than I do
alan
I can open the files ending in InjectorsModule from my mac using android studio. They open as kotlin files but do not have the "C" for class like other kotlin classes
Mark M.
perhaps it's not a pure class file
alan
yeah dagger generates a whole bunch of factory classes that pollute my search results so I tried to exclude some
unfortunately I think that may be causing the issue I am facing
Mark M.
possibly, though the Kotlin icon issue may be unrelated
alan
OK that is good to know
Mark M.
the decision for how Android Studio chooses which to show as classes or just as generic Kotlin file is strange
you definitely get a plain Kotlin icon if there are 2+ classes in the file
or if there are zero classes in the file (e.g., just extension functions)
alan
I don't see any custom scopes anymore but those files still don't show in global search, and even don't show in the project view
Mark M.
yeah, I haven't done anything like that, sorry
alan
OK, btw I don't think the C stands for ".class files if that's what you meant. I have a fragment that has the C icon
4:25 PM
Mark M.
it seems to mean "Kotlin class", as they have different icons for interfaces and objects
plus the generic "Kotlin file" icon
but, the precise rules are confusing, so I don't really pay a lot of attention to the icon
alan
you're right about the icon being an unrelated issue
I just noticed I had a file that was mispelled, but also an abstract class that shows in the project view. it shares the same icon as the missing file
Mark M.
¯\_(ツ)_/¯
alan
this is driving me nuts because git shell acknowledges its existence and yet android studio vcs git doesnt
anyway how do I reset my android studio settings
Mark M.
well, the nuclear option is to delete the directory that holds them
e.g., ~/.AndroidStudio3.3 for Android Studio 3.3.x
4:30 PM
Mark M.
the settings are mostly in XML files, so it's possible you could find the file(s) that seem to be referring to that name fragment and make manual changes
though I'd back up that directory first :-)
alan
good idea ;)
4:35 PM
alan
strange I cannot find that dir
Mark M.
what OS are you running?
alan
mac
Mark M.
hmmm... AFAIK it would be in the same location there as on Linux (where I am)
you sure you're seeing hidden (dot-prefixed) directories?
alan
ls -a | grep AndroidStudio3.2 does not return anything
4:40 PM
Mark M.
perhaps they use a different system on macOS
alan
OK
Mark M.
I expected it to be consistent
alan
if I deleted this directory would that uninstall android studio
Mark M.
no, there is a separate directory with the binaries and stuff
this is just a configuration directory
alan
where are the binaries located?
Mark M.
wherever you put them :-)
presumably in the standard locations for macOS app installs
I don't do a lot with macOS, so I don't know the details
alan
sorry you mean the Android Studio.app?
Mark M.
I guess
if you have ever moved to a newer Android Studio and got the "do you want to import your settings?" dialog on first run, that is because Android Studio is looking for its version's edition of the settings and not finding it
on Linux, at least, that is based on the existence of the .AndroidStudioX.Y directory for a given X.Y version
alan
yeah i think i saw it
Mark M.
ahhh...
looks like they might put this stuff in ~/Library/Preferences
(and I apologize for Stack Overflow's, um, creative UI for April Fool's...)
4:45 PM
alan
thanks I'll check it out
another question I wanted to confirm about android lifecycle. Suppose I logged in to the app and navigate to a details screen. if that details screen runs out of memory, android exits the app and takes me to the next app in its list. If I click the launcher do I see the login screen or the details screen
4:50 PM
Mark M.
my guess is the login screen, but that's just a guess -- I have not tested this specific scenario
alan
maybe the login screen is not a good example as most apps may not have a way to reauthenticate. I actually tried something similar but replaced the login screen with a regular activity. It went to the details activity
Mark M.
sorry, again, I have not played with that particular scenario
alan
I have an application that does this for me(simulate an OOM exception). My friend mentioned there was a setting in developer options to simulate this. Do you know what that is?
Mark M.
I haven't heard of an option to simulate an OOM from Settings
alan
OK
I thiought it was "clear activities" but it had a different effect
4:55 PM
alan
well anything to kill the app process i meant sorry
Mark M.
for terminating a background process without affecting the task, I use adb shell
adb shell am kill ..., where ... is your applicationId
however, that does not simulate an exception in that process
alan
it was to test state restoration
Mark M.
then adb shell am kill should work
alan
OK thank you.
alan
has left the room
5:00 PM
Mark M.
turned off guest access

Thursday, March 28

 

Office Hours

People in this transcript

  • alan
  • Anshul Vyas
  • Mark Murphy