0

I have application that uses the SlidingMenu library. It' is essentially a Fragment in the main Activity that goes in and out of view when user swypes (e.g Youtube, Google+, Facebook).

The top LinearLayout in this SlidingMenu has some Dynamic information in it. Such as Login and other info that changes as the users interacts within the app.

One example: The user opens app, that layout in SlidingMenu says "Log in". They go into overflow menu, start Login Activity (over MainFragmentActivity), signs in successfully, and Login Activity dissapears. Next time they swipe the menu open, they should see their user name, profile stats, profile picture, etc.

My question: How do I dynamically change this layout without using a refresh button?

Does this include using:

onCreateView() method in the fragment?

Note: Currently, it only updates when app starts. It starts an AsynTask to download things from MySQL. It seems like a waste of resources to hit the DB everytime user opens the panel, is there a more efficient way of using this?

Ahmad
  • 69,608
  • 17
  • 111
  • 137
TheLettuceMaster
  • 15,594
  • 48
  • 153
  • 259
  • 1
    You'll want to cache the content on the phone itself (probably in sqlite), you'll want check for new remote content at intervals when your application is in the foreground, and/or perhaps even use something like Google Cloud Messaging to ping your application in case the data needs to be refreshed rapidly -- but irregularly (like you would have to do with a chat application or a twitter client). – Stephan Branczyk Apr 16 '13 at 23:07
  • Thanks. If I have the time, I may even expand on it, or perhaps someone else will get to it before I do. By the way, what kind of content are we talking about? Does it need to be secure? Do you envision yourself using Google Cloud Messaging? Or would that be overkill? Also, is your connection to MySQL a direct database connection, or are you using a php web server in between? – Stephan Branczyk Apr 16 '13 at 23:50
  • @StephanBranczyk To answer your questions: Information is not sensitive. Just username, scores, ranks, things like that. Will be using GCM in a different area of the app (message notifications). Don't know anything about it yet--need to research! MySQL connection is done via php. The app is almost a mini-social network like functionality. – TheLettuceMaster Apr 17 '13 at 16:07

2 Answers2

1

You'll want to cache the content on the phone itself (probably in sqlite), you'll want check for new remote content at intervals when your application is in the foreground, and/or perhaps even use something like Google Cloud Messaging to ping your application in case the data needs to be refreshed rapidly -- but irregularly (like you would have to do with a chat application or a twitter client).

Stephan Branczyk
  • 9,363
  • 2
  • 33
  • 49
  • Can you give me an example of what content needs to be cached? For example, the dynamic aspect contains a user score. I load score from MySQL when app starts. Should I add to it dynamically by caching that number in `SQLite` in the background and work with it that way (yet will send info to `MySQL` database (just no need to return it for results)? – TheLettuceMaster Apr 17 '13 at 16:09
  • @KickingLettuce, What kind of score is it? Is it a score from a game played with your android device? Or is it a sports score or a score from an online game not played through the device? Also is it a single score? How elaborate is that score? Do you also keep a ranking of other players at similar levels? The reason I'm asking is because using sqlite may be overkill for a single score. – Stephan Branczyk Apr 17 '13 at 20:44
  • Its a single user score. As they interact with the app, some things add to their score. The score also effects a ranking and level which are also updated in the same Layout. But those are all conditional based on the score. For example. 5000 points moves you to the next level. A Domino effect. – TheLettuceMaster Apr 17 '13 at 23:02
  • 1
    Ah ok, the single score is actually generated on the device and updated online for the rankings? Correct? This means that if the user didn't have an internet connection, he should still be able to view his own score (the value of which could be stored in a local user preference). The query of similar scores for ranking purpose could be done later, when the user actually opens an activity to see his ranking. And the uploading of his score to the server-side could be done every time he checks his ranking, and/or just once in a while with AlarmManager and a service that does it asynchronously. – Stephan Branczyk Apr 18 '13 at 00:32
1

As Stephan mentioned, you can cache the data in SQLite, on top of that, you can use contentProvider, to return you a Cursor on the data stored such as login name.

Now the benefit here is that when the user logs in, you can call update in contentProvider, updating the value, and then call contentResolver.NotifyChange which will update the result in the cursor, in turn automatically update what is in the slidingMenu.

wangyif2
  • 2,843
  • 2
  • 24
  • 29