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?
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).
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.
Related
I'm building a somewhat basic app (only testing on Android for now) with multiple lists, one of which is an Inbox list. I can share text from other apps to my app, and it works well.
However, I would like the app to handle the intent without launching the full app UI. For example, if I share a URL from the browser to my app, I would like it to be handled in the background, save the URL to Firestore, and show a toast to the user indicating that it was successful.
Ideally, I would like to put two entries in the share menu, one to add to the Inbox and show a toast as described above, and a second entry that gives the user a modal dialog that floats above the sharing-from app, which allows the user to choose a different list to save to.
I think I'll have to make a (for example) ShareActivity.java, and add it to AndroidManifest.xml, but I have no idea where to go after that, or even if that's the right approach.
Recently was given the opportunity to create an Android app for my college group. But I was not satisfied with the event page. I wanted to create a dynamic page in which admin can update the upcoming events. On using URI the images were a bit off. Can anyone help me?
If you want to create Event Page which can be changed dynamically, you should design a page such that, you give a provision of adding Events, displaying it and
refreshing the UI.
I would suggest before start implementing an App, you should gather requirements, define the features of the App, Design the App and then go after implementing.
You can use Firebase storage and Real-time database to store data and images. Also, create an admin application for changing the image.
You can have provision to add an event, persist the event details by using either database or webservice, and updating the event.
The create event page can be made dynamic by having provisions to add/subtract event detail items from the screen. For example: Use can have a section saying Number of day(s) and a + button besides it to add details about each added day.
If you want only admin user to be able to add, update, and delete the event you can use role based login (for login again, you can use either database or webservice).
These are just rough ideas, but its necessary that you freeze the requirements before jumping into designing the app.
I've watched the Coursera android course and I have doubts how Android works in my application that I'm building. It does basic stuff, like register and show my info and do TODO using server as database. And I know it depends how I want to it begin built. Need some options.
Fragments can be built in ActionBar and whenever I want be called? Or is it bad to this way and stick with default menu built and hide it programmatically? Tried to google and didn't find any information.
The MainActivity is made to make http request POST to register name, email and password in my server. Is it possible to start the SecondActivity whenever he logged in? It's just like Instagram. But, I could set a condition to check depends if logged or not change the setContent(R.layout.main) or setContent(R.layout.second)?
When the register is done. All the data is saved on the server. But I want to check every time he changes activity or do some action if he's logged in or not. Could I use some thread with a flag(bool)? Could be a bad practice and reduce the performance? Or SharedPrefrences adding flag(bool)? But SharedPreferences are saved after the application is closed?
About to show my information in every Activity, like name, age and sex etc and such. Making request http just to show information is quite bad for my application, since it's just TODO app and I don't need to be connected to internet to see my info, but in case of edit, yes. So if I save in the SharedPreferences, but stays the same doubt, it will save after I close the application?
Since your question is likely to be drastically edited (as i advised in a comment) i quote the original text here.
Fragments can be built in ActionBar and whenever I want be called? Or
is it bad to this way and stick with default menu built and hide it
programmatically? Tried to google and didn't find any information.
Yes, fragments can be used whereever you like. But thats not really an answer.
Base your design on the various activities (think "what app screens should users navigate", and give these one fragment each.
The MainActivity is made to make http request POST to register name,
email and password in my server. Is it possible to start the
SecondActivity whenever he logged in? It's just like Instagram. But, I
could set a condition to check depends if logged or not change the
setContent(R.layout.main) or setContent(R.layout.second)?
Yes, you could have a LoginActivity that is called with startActivityForResult(). It would connect and return the success/failure. (See http://developer.android.com/training/basics/intents/result.html )
Also, keep in mind that HTTP POST is not encrypted, the password is sent as plain text.
When the register is done. All the data is saved on the server. But I
want to check every time he changes activity or do some action if he's
logged in or not. Could I use some thread with a flag(bool)? Could be
a bad practice and reduce the performance? Or SharedPrefrences adding
flag(bool)? But SharedPreferences are saved after the application is
closed?
Yes, SharedPreferences are stored after exiting the application. Ideal to simply implement app settings, but when storing lists of items you should look into other solutions. A JSON file may be of use, you could directly pull/push it from/to server.
About to show my information in every Activity, like name, age and sex
etc and such. Making request http is quite bad for my application,
since it's just TODO app and I don't need to be connected to internet
to see my info, but in case of edit, yes. So I saved in the
SharedPreferences, but stays the same doubt, it will save after I close the application?
See answer above. In short get a JSON string from the server, store it locally in a file. View and edit the local file, then upload it whenever you want. This way it works offline too, but can still download/upload the changes.
Hi i was wondering if it was possible to create a Sidebar for an activity that would allow a user to select a few options such as extra information that can be associated with an object. before sending it off to a server through an API I have looked at trying to use Googles own Nav bar as well as a few Third party libraries that dont seem to want to work for me.
Encase you dont understand what im trying to achieve ill give an example:
Say i have an activity that allows the user to create a log for a specific group within the app now the user may press submit and it will be sent off to the server to be stored in a Database but the user can also associate other aspects to this log such as a book id or an activity ID.
So the user should able to pull a side bar from the side and select any extra information they need (probably from spinners or extendable listview) and then go back to the main activity and submit the log.
Is there anyway of creating anything like what im asking with out having to dig into third party libraries?
You can define arbitrary layout for your NavDrawer (I will use the name of android component here). There is no enforcement to navigation here. So, put in NavDrawer's layout a bunch of controls that you need and define their onClick, onSelected, etc. methods to handle corresponding properties changing. On submitting just get checked/selected/entered info from controls in NavDrawer, augment your data with it and send to server.
I've downloaded a few networking apps (games) that have you log in, then take you to a "home" type screen where you can change your settings, or start a new game, or view your buddies etc.
My question is two-part:
1) how are these "multipanel" apps created? Is each panel its own activity? I've tried adding different panels through Views, but on the apps I described above, when I hit the back button on my phone, it takes me to the previous screen and in my apps, it just takes me out of the app when I hit back (again I'll I've done are add separate views). Can someone point me in the right direction of what I need to do to create a multipanel application that when I click a button, a new panel loads, then when I hit back on the phone, it takes me to the previous panel?
2) one of my panels will be a login page which I will post the log-in credentials via http post to my server for authentication. I would like to remember the log-in "token" that is passed back to the client so they don't have to log in every time they use my application. Again, referring to some of the apps that I have, they offer this feature but I can not locate anything on the phone where it would be saved. Is this done with xml usually?
Thanks for your time.
1 - I agree. They are most likely separate Activities. To open another activity, you just use an intent, like this:
Intent intent = new Intent(MyActivity.this, NewActivity.class);
startActivity(intent);
2 - It sounds like the SharedPreferences class is the way to go, but read through the Android documentation for storing data, since there are a number of ways to go about saving data:
http://developer.android.com/guide/topics/data/data-storage.html
http://developer.android.com/reference/android/content/SharedPreferences.html
1) Yes, these are probably separate Activities. There's also a possibility that they're capturing the Back Button press and switching views, but that's a pretty awkward way to do it.
2) You can save the data with SharedPreferences or in an SqLite database.