Office Hours — Today, December 8

Thursday, December 3

Dec 8
7:25 PM
Mark M.
has entered the room
Mark M.
turned on guest access
Chandra S.
has entered the room
Mark M.
hello, Chandra!
Chandra S.
Hi Mark
Mark M.
how can I help you today?
Chandra S.
I actually new to the new Android SDK dev so sorry if I ask the noob question :-)
Mark M.
go right ahead
Chandra S.
I want to ask about strategy for data persistence to store user session, like userid, etc. If the device rooted, then the shared preferences data can be changed right? So user can change that. Should the data be encrypted or what is the best practive?
Mark M.
well, the user probably knows the user's user ID
so, I am not sure why you are worried about encrypting a user ID
if the user changes their user ID, either your server will not recognize the user ID, or the user will not know the password of the changed user ID
the best practice is to put your defenses on your server
7:30 PM
Chandra S.
I see.. Got it, Mark.. So implement like key in the REST communication
Mark M.
something along those lines, yes
Chandra S.
OK.. I also confuse about choosing fragment or activity, whether my application use 1 activity and many fragments on top of that or many activity?
Mark M.
either is fine
the reason fragments were introduced is to help make it easier to support larger-screen UIs, such as for tablets
Chandra S.
Is there any cons from the memory used if I use activity only?
Mark M.
the belief being that you might be able to decompose your UI into phone-sized chunks, showing one at a time on phone-sized screens and more than one at a time on larger screens
not really
I would not expect memory consumption to change much, at least for ordinary use cases
Johnny
has entered the room
Mark M.
there are some cases where going with a single activity can be very useful, due to the limitations of passing data between activities using Intents
(BTW, hello, Johnny -- I will be with you shortly!)
Chandra S.
I'm reading the Telegram source and they use only a few activity only, so I'm little bit confuse
Johnny
Hi Mark
Mark M.
Chandra: that was their design decision to make
I don't use Telegram, and so I have no idea what their UI looks like on phones or tablets
again, there is nothing wrong with using either fewer activities (backed by fragments) or in mostly using activities
Chandra S.
OK.. How about changing transition between Activities? Like for example making it slide from right?
7:35 PM
Mark M.
I haven't played with that, sorry
I know that there are some hooks for changing activity transitions, but personally I would leave that alone
let me take a question from Johnny, and I will be back with you shortly
Johnny: your turn! do you have a question?
Chandra S.
OK Mark..
Johnny
View paste
I'm trying to get a simple box, to show up inside a relativeLayout and it doesn't seem to be appearing on the emulator. It shows in the preview though
<View
 android:id="@+id/box”
 android:layout_width="20dp"
 android:layout_height="match_parent"
 android:layout_alignParentLeft="true"
 android:background="@color/black” />

sorry for formatting
Mark M.
in general, use Hierarchy View or uiautomatorviewer to examine the UI as it is being displayed in the emulator, to try to determine where your box has gone
Johnny
ah ok I'll check that out, thanks
Mark M.
beyond that, post the layout XML somewhere, and perhaps I can see something amiss in the layout
7:40 PM
Mark M.
while you are working on that, let me take another question from Chandra, and I will be back with you in a bit
Johnny
I'll see if I can work it out first, thanks :)
Mark M.
Chandra: your turn! do you have another question?
OK, if either of you have a question, go right ahead
Johnny
Also just wondering, have you played around with ripple effect and elevation?
7:45 PM
Chandra S.
Just check whether I'm disconnected or not :-D
Mark M.
hmmm... Campfire may be having a bad day
Johnny
Problem I have is, I can't seem to get ripple effect and item being raised effect happening at the same time when I press a view. It animates fine, but only does the ripple effect after I leave the touch area
Mark M.
Johnny: I did some work with ripples with RecyclerView, but otherwise not
and I have not messed with elevation much
definitely not changing elevation on the fly in response to touch input
sorry
Johnny
No worries
Mark M.
Chandra: I am not sure whether the problem was on my end or Campfire's, but you're not disconnected AFAICT
7:50 PM
Johnny
View paste
ok just regarding my ripple question, it turns out that's meant to be the desired effect. So ignore that.
I just did a dump on my entire view and the box view isn't there. Seems like it has been stripped out. Odd
Mark M.
is it a fixed part of the layout XML, or are you adding it dynamcally?
er, dynamically
Johnny
fixed
Mark M.
do you have android:visibility="gone" on it? are you toggling visibility on it at runtime?
7:55 PM
Chandra S.
Hi Mark, Johnny, since there's no discussion can I ask again?
Mark M.
Chandra: yes, go right ahead -- right now, it is open for anyone
particularly given the connection issues
8:00 PM
Johnny
View paste
Just leaving this here, 

Actually interesting.. it's showing if I have height as a fixed heigh, but if I do match parent, it doesn't show. This is all inside a relative layout, inside a cardview
Mark M.
Johnny: what else is driving the height of the RelativeLayout?
Chandra S.
Ah I didn't see any conversation up there until I quit and rejoin
Johnny
This is inside a recyclerview
Chandra S.
Related to our last conversation on fragment or activity, what kind of data that can't be pass easily between activities so in that case we have to use fragment? Could Singleton did that?
Johnny
I'll let Chandra go first
Mark M.
Chandra: big data (>1MB, like a photo) or data that cannot go into Intent extras
those become more difficult to pass across to another activity
Chandra S.
I see.. OK.. Still related to the data persistence, I have a list of data to be shown in Recyclerview, still confuse on how to combine the Singleton and SQLite, and sync the data to the server.
Mark M.
I am not sure what "the Singleton" is
typically, you have a single instance of SQLiteOpenHelper
whether that is a singleton, or is managed by something else, depends on implementation details
in terms of syncing data to the server, an IntentService is a typical solution
whether triggered by user input, on a scheduled basis (e.g., JobScheduler or AlarmManager), etc.
Johnny: my earlier point was that if nothing else is forcing the RelativeLayout to a certain height, match_parent on a child of the RelativeLayout will not force it to a certain height, so the RelativeLayout might have a height of 0
Chandra S.
I see.. OK..
Mark M.
I assume, though, your RelativeLayout has other stuff beyond the missing box in it, like TextViews or ImageViews or something
8:05 PM
Chandra S.
View paste
I have a question regarding internet access, previously I have been playing with the old SDK years ago.. I was using DefaultHttpClient and HttpPost which have been deprecated. Things like NameValuePair also deprecated. Which one you recommend for now?
Mark M.
well, here's the Stack Overflow I point everyone to: https://stackoverflow.com/a/32951118/115145
personally, I use OkHttp, or things layered atop of it (e.g., Retrofit, Picasso)
Chandra S.
Got it, Mark
I also still confuse about LayoutInflater, on what it actually did
Mark M.
it, um, inflates layouts :-)
it takes the layout XML and returns the tree of Views and ViewGroups defined in that XML
Chandra S.
So the onCreateView method was called by the hosted activity right?
Mark M.
either that or by the FragmentManager
8:10 PM
Mark M.
I seem to recall looking at the LayoutInflater code once or twice and concluding that it is pretty nasty
Chandra S.
View paste
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
View result=inflater.inflate(R.layout.mainfrag, container, false);
return(result);
}
That code?
Mark M.
no, the implementation of LayoutInflater itself
Chandra S.
I see.. Since I'm looking at this code and still confuse who call the method, what container was giving, since it just pass the container to the inflate method
Mark M.
that depends on how the fragment is being added to the activity
(BTW, Johnny, if you have additional questions, go right ahead, and I'll take 'em as they come in)
Chandra: if you are using dynamic fragments, with a FragmentTransaction, you supply the container
if you are using static fragments (<fragment> tags in a layout), then a FrameLayout(?) is created for you by LayoutInflater, and that is the container
Johnny
View paste
Here's my xml layout. http://pastebin.com/ujrNsHrF

So it is definitely got to do with the height. So it seems like when it's trying to measure the heigh using "match_parent", at that time, there is no height so it removes it
Chandra S.
Ah I see.. Got it, Mark..