Aug 28 | 8:50 AM |
Mark M. | has entered the room |
Aug 28 | 8:55 AM |
Mark M. | turned on guest access |
Aug 28 | 9:10 AM |
trocchietto_Ivano | has entered the room |
Mark M. |
hello, Ivano!
|
Mark M. |
how can I help you today?
|
trocchietto_Ivano |
HI Mark good morning! Yesterday you casually helped me on so
|
trocchietto_Ivano |
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
|
Mark M. |
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)
|
trocchietto_Ivano |
I imagined that
|
trocchietto_Ivano |
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
|
trocchietto_Ivano |
I am wondering what I have to do to debug startActivity, i went into the internals and discovered that is triggered by some startActivityForEvent
|
Aug 28 | 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,
|
trocchietto_Ivano |
not at all
|
trocchietto_Ivano |
this is the mystery
|
trocchietto_Ivano |
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
|
trocchietto_Ivano |
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
|
Mark M. |
you are calling startActivity(), and something is coming onto the screen
|
trocchietto_Ivano |
how can i achieve that?
|
trocchietto_Ivano |
this is correct Mark!
|
trocchietto_Ivano |
an empty activity
|
Mark M. |
the simplest solution would be to start the Layout Inspector
|
trocchietto_Ivano |
but log does not bring me nothing
|
trocchietto_Ivano |
nor breakpoint
|
trocchietto_Ivano |
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
|
trocchietto_Ivano |
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
|
Mark M. |
IIRC = "if I recall correctly"
|
trocchietto_Ivano |
:)
|
trocchietto_Ivano |
if would be as you reckon... why onCreate is not called? I have even put a log before of the super method
|
Aug 28 | 9:20 AM |
Mark M. |
since I don't have the code, I cannot readily answer that
|
Aug 28 | 9:25 AM |
trocchietto_Ivano |
this is the activity target https://bitbucket.org/trocchietto/bezinning/src...
|
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 | |
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
|
trocchietto_Ivano |
no
|
trocchietto_Ivano |
because in the main activity I put a lot with intent
|
trocchietto_Ivano |
and the breakpoint says that has extras
|
trocchietto_Ivano |
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
|
Aug 28 | 9:30 AM |
trocchietto_Ivano |
I am gonna to ascertain before that L inspector is targeting my promised land activity
|
Aug 28 | 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)
|
trocchietto_Ivano | |
trocchietto_Ivano |
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!
|
Aug 28 | 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!
|
trocchietto_Ivano |
i am going to check about the structure now
|
trocchietto_Ivano |
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!
|
trocchietto_Ivano |
do you mean target activity?
|
Mark M. |
yes, the one whose code you provided here in the chat
|
Mark M. |
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:) )
|
trocchietto_Ivano |
yes it takes PersistentBundle? as the second parameter
|
Aug 28 | 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
|
Mark M. |
as that is what that *vast* majority of activities do
|
Mark M. |
and you seem to be having a problem where this two-parameter onCreate() is not being called
|
trocchietto_Ivano |
you are a god
|
trocchietto_Ivano |
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!
|
trocchietto_Ivano |
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!
|
trocchietto_Ivano |
ehy Mark, I have a meta question regarding that
|
trocchietto_Ivano |
is about context in general
|
trocchietto_Ivano |
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
|
trocchietto_Ivano |
for instance injection,
|
trocchietto_Ivano |
otherwise a get in application
|
Aug 28 | 9:50 AM |
trocchietto_Ivano |
or as you told me to use it from the onBindViewHolder passing view.getContext()
|
trocchietto_Ivano |
my question is ... is the context always the same?
|
Mark M. |
no
|
trocchietto_Ivano |
after all is a class
|
trocchietto_Ivano |
???
|
trocchietto_Ivano |
I am really curios about this black magic
|
Mark M. | |
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
|
Mark M. |
in general, Context is a mess
|
Mark M. |
but for the purposes of a startActivity() call from the UI, you want a Context that is tied to the UI
|
Mark M. |
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
|
Mark M. |
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
|
Mark M. |
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?
|
Aug 28 | 9:55 AM |
trocchietto_Ivano |
I mean is a singleton instance
|
trocchietto_Ivano |
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
|
trocchietto_Ivano |
this is awesome
|
trocchietto_Ivano |
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?
|
trocchietto_Ivano |
where the green ants dream
|
Mark M. |
it's really rather complicated
|
Mark M. |
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
|
trocchietto_Ivano |
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
|
Mark M. |
anyway, I am glad that you have things working better now
|
trocchietto_Ivano |
yes I am getting diabetes for all that syntactic sugar
|
trocchietto_Ivano |
thanks
|
Mark M. |
LOL
|
trocchietto_Ivano |
and I wish you a pleasant day
|
Aug 28 | 10:00 AM |
Mark M. |
and to you as well!
|
trocchietto_Ivano |
thumb up
|
Mark M. |
that's all for today's chat
|
Mark M. |
the next one is Thursday at 7:30pm US Eastern
|
Mark M. |
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 |