Office Hours — Today, August 28

Saturday, August 25

Aug 28
8:50 AM
Mark M.
has entered the room
8:55 AM
Mark M.
turned on guest access
9:10 AM
trocchietto_Ivano
has entered the room
Mark M.
hello, Ivano!
how can I help you today?
trocchietto_Ivano
HI Mark good morning! Yesterday you casually helped me on so
but still does not work. Basically I have a recyclerView and on click of an item I want to launch an activity with the content of the item, a String
Mark M.
yes, I remember that question -- I did not realize that was you
I was confused by some of your follow-up material in that question, which is why I did not respond further
trocchietto_Ivano
you suggested me to pass in the Adapter the context extending it fromthe view(yes was me with one of the accounts I use to ask questions)
I imagined that
basically I am really surprised that even if in MainActivity I cancel the fragment call and just pass an explicit intent to launch an activity! does not work
I am wondering what I have to do to debug startActivity, i went into the internals and discovered that is triggered by some startActivityForEvent
9:15 AM
Mark M.
my understanding was that you were successfully launching the activity, but you were not getting the results in that activity that you were expecting
trocchietto_Ivano
and get a code -1 if does not work,
not at all
this is the mystery
an activity is launched but is empty!
Mark M.
so, your problem would seem to be in that activity
trocchietto_Ivano
completely, I tried to put TextView hardcoded to recognize which Activity was, but nothing happens, is like startActivity(intent) does not start my target at all!
Mark M.
well, it's triggering something
trocchietto_Ivano
I am wondering could be that since I have APPLication that is starting Dagger2, the cycle of the dependencies could mess up the original context
so my first curiosity is there are different contexts?
Mark M.
well, sure
trocchietto_Ivano
i tried also getAPplicationContext
Mark M.
I would start by determining exactly what is coming onto the screen
you are calling startActivity(), and something is coming onto the screen
trocchietto_Ivano
how can i achieve that?
this is correct Mark!
an empty activity
Mark M.
the simplest solution would be to start the Layout Inspector
trocchietto_Ivano
but log does not bring me nothing
nor breakpoint
mmh
Mark M.
if you have multiple activities running, the Layout Inspector should show you a drop-down of those activities
trocchietto_Ivano
great suggestion Mark
cool
Mark M.
and from there, you can identify the class that is the activity that is in the foreground
trocchietto_Ivano
that is the last one
Mark M.
yes, IIRC
trocchietto_Ivano
IIRC?
Mark M.
my guess is that it is indeed the activity that you are expecting, but there are problems in that activity's implementation
IIRC = "if I recall correctly"
trocchietto_Ivano
:)
if would be as you reckon... why onCreate is not called? I have even put a log before of the super method
9:20 AM
Mark M.
since I don't have the code, I cannot readily answer that
9:25 AM
trocchietto_Ivano
reallly small
Mark M.
have you confirmed that it is what is being started by your startActivity() call?
trocchietto_Ivano
I am checking with L inspector
Mark M.
depending on what else is in R.layout.bezinning_content, your UI might be empty if EXTRA_MESSAGE is null, blank, etc.
trocchietto_Ivano
this is bezinning_content
Mark M.
right, so if EXTRA_MESSAGE is null, empty, etc., you would wind up with a blank UI
trocchietto_Ivano
I added also a TextView with text attribute hardcoded ciao
no
because in the main activity I put a lot with intent
and the breakpoint says that has extras
lot=log
Mark M.
perhaps the extras are using different keys, and so your startActivity() call is using an Intent that does not have EXTRA_MESSAGE
9:30 AM
trocchietto_Ivano
I am gonna to ascertain before that L inspector is targeting my promised land activity
9:35 AM
trocchietto_Ivano
Mark, you were right!
Mark M.
yay! but, um, what did I get right? :-)
trocchietto_Ivano
actually the L inspector asked me to chose between two activities furnishing me the snapshots, one is main activity that shows the rec view (because the fragment is on top)
View paste
and the other one is target activity that is completely empty!
I am trying to change name in the manifest to have a double check
Mark M.
"completely empty" meaning that your layout did not load, or that the layout is there (ScrollView, RelativeLayout, and TextView), but that the text is empty?
trocchietto_Ivano
nice question I am checking
Mark M.
the Layout Inspector output will show you the view hierarchy for your selected activity
trocchietto_Ivano
oh mark!
9:40 AM
trocchietto_Ivano
I added a label attribute in the manifest" ciao" and also without L inspector now on click I can see that the activity with the action bar ciao is triggered!
i am going to check about the structure now
i have indeed a structure Linear Layout/Frame Layout/decor_content(ActionBarOverlayLayout/actionBar(Toolbar)
Mark M.
in your activity, you are overriding the onCreate() method that takes persistentState: PersistableBundle? as the second parameter
trocchietto_Ivano
then on the same level of LinearLayout I have navigationBarBackground(View) and statusBarBackground(View) is so beautiful to go so deep and let the magic away!
do you mean target activity?
Mark M.
yes, the one whose code you provided here in the chat
since you are not using that PersistableBundle, perhaps override the classic onCreate() that only takes a Bundle, since it feels like your current onCreate() is not getting called
trocchietto_Ivano
(sorry as you see I have problem with context:) )
yes it takes PersistentBundle? as the second parameter
9:45 AM
trocchietto_Ivano
so can i set it as null
Mark M.
I am suggesting that you get rid of it, and override onCreate(savedInstanceState: Bundle?) instead
as that is what that *vast* majority of activities do
and you seem to be having a problem where this two-parameter onCreate() is not being called
trocchietto_Ivano
you are a god
is working
Mark M.
I have not looked at the PersistableBundle stuff in quite some time, since it never seemed to be that popular
trocchietto_Ivano
tomorrow a company invited me for a second interview, if they take me and I will focus on android I will become better than you. promised!
but how do you come to this solution?
Mark M.
I wish you luck!
trocchietto_Ivano
I would neve never understood that!
Mark M.
10 years of dealing with Android, I suppose
trocchietto_Ivano
thanks for the good luck!
ehy Mark, I have a meta question regarding that
is about context in general
can i bother you with that one?
Mark M.
sure
trocchietto_Ivano
well before to posto on SO, I already found that there are a bunch of ways to pass the context
for instance injection,
otherwise a get in application
9:50 AM
trocchietto_Ivano
or as you told me to use it from the onBindViewHolder passing view.getContext()
my question is ... is the context always the same?
Mark M.
no
trocchietto_Ivano
after all is a class
???
I am really curios about this black magic
Mark M.
this is a bit old, but it is one of the best discussions of the roles of different types of contexts that I have seen
in general, Context is a mess
but for the purposes of a startActivity() call from the UI, you want a Context that is tied to the UI
a View's Context is going to be tied to that UI in normal circumstances
trocchietto_Ivano
ah
Mark M.
and you had a View available
so, that was an easy way to get a suitable Context
trocchietto_Ivano
so I passed the context of the main Activity
Mark M.
that too can work
but using getApplicationContext() would not, as you would get an error asking if you wanted FLAG_ACTIVITY_NEW_TASK (at least on many versions of Android)
trocchietto_Ivano
why is that?
9:55 AM
trocchietto_Ivano
I mean is a singleton instance
so is like Europe and I am in the Netherlands
Mark M.
yes, but then it is not tied to any particular task (back stack of activities), and your app can have several of them
trocchietto_Ivano
I see
Mark M.
an activity is part of a task, so starting another activity from that first activity's Context just keeps the new activity in the same task, unless you take steps to change that
trocchietto_Ivano
because Activity inherith from an internal context that is linked to ContextWrapper
this is awesome
so basically is correct to say that I can use context in an Activity because there is a super method in Oncreate that refer to A context class up to the hierarchy?
where the green ants dream
Mark M.
it's really rather complicated
usually I just say "an Activity is a type of Context" and go with that
trocchietto_Ivano
perfect
Mark M.
but, yes, there is a ContextWrapper involved
trocchietto_Ivano
but one day will hack that
Mark thank you very much and my compliments also for your fluency in Kotlin
Mark M.
I'm getting better with Kotlin, but it is a rather complex language
anyway, I am glad that you have things working better now
trocchietto_Ivano
yes I am getting diabetes for all that syntactic sugar
thanks
Mark M.
LOL
trocchietto_Ivano
and I wish you a pleasant day
10:00 AM
Mark M.
and to you as well!
trocchietto_Ivano
thumb up
Mark M.
that's all for today's chat
the next one is Thursday at 7:30pm US Eastern
the transcript of today's chat will be up on https://commonsware.com/office-hours/ shortly
trocchietto_Ivano
has left the room
Mark M.
turned off guest access

Saturday, August 25

 

Office Hours

People in this transcript

  • Mark Murphy
  • trocchietto_Ivano