I would like to be able to have an app that loads button fragments; when the user presses any button, it goes to their specific website.
I am trying to use a switch statement, it works on the first button/website but won't load other websites for their respective buttons.
I have been doing it in the onCreateView class since that is the source to switch between each button and their actions.
In my app i have button when it clicked the app goes to another activity with webView to show HTML table
The issue here is when i press back and return to the same activity the webView load agin and it take while how can i prevent it from loading over and over agin and will turnning the HTML table to listview will make it loade faster if yes . How ?
You can Preserving the state of an Android WebView on screen orientation change or activity is paused.
If you’ve tried to use a WebView inside your app, you know that the standard behavior on screen orientation change is not satisfactory in most cases because the full state of the WebView is not preserved or similarly when your activity is pause same situation WebView will change their sate.
possible implementation to keep the full state of the WebView
here complete tutorial and code is given you can get idea from this code&tutorial
Hello I require some advice on how to approach this problem,
bear with me as I am still new to android.
I have an activity that opens on application start and requires some information from the user, but next time the user opens the app, i want the application to open a different activity that will display the various information.
Kind of like facebooks app, where when you first run it, you have to login, and only then next time you run the app you are guided straight to the feed.
Any ideas how one could do this efficiently?
UPDATE: Ive stored the information via shared preferences and am now using a controller activity that decides which step to take.
So, Controller activity runs on start up, and decides whether to show a log in screen or whether to go straight to the information. But now im encountering a problem where i end up opening a blank activity (the controller) and then another ontop of that ( the decided activtiy). I dont want the blank activity to show, so its kinda of like a background process, any ideas?
Ideally you would have a main activity like a controller. Use a SharedPreference object to keep track of whether the user is logged in or not. So back in your main activity, read this value and if it is set go to your news feed activity else show a login screen activity. (as you do the check and redirection, you can show a progress dialog)
links for SharedPreferences
MobTuts
Android Developer
I have this app that originally has you take a picture, shows you a progress bar, and uploads it to a website.
What I want to add is something so that before the progress bar shows, an Intent starts an activity that loads a layout with a dropdown menu that allows you to choose a descriptor for the picture. Following this, once you hit the 'OK' button on this new layout, the program should return back to where it had left off and display the progress bar.
Does anyone have any ideas on how to achieve this?
It seems that all I really want is some way to tell the program to stall for a while to call an intent, and when the user hits 'OK', the code may resume.
You should be using OnActivityResult().. More information on the link below http://developer.android.com/reference/android/app/Activity.html#startActivityForResult(android.content.Intent, int)
When the user opens the application, there is a screen with a button on it, which says "login."
The user clicks on the button, and a webview pops up to allow him to log in to the website.
After logging in (the app would need to know somehow), the webview would disappear, and then a list of usernames will pop up. (ListView?)
When the user clicks on one of the usernames, a webview of the username's profile will pop up. Of course, when the user pushes "back", it goes back to the list of usernames.
Can someone explain this to me in terms of Activity and Views? Am I using two activities to do this? Do I hide webview or listview when the user clicks between them?
I did the tutorial (notepad tutorial), but I'm still confused as to what is the best way to develop this.
Thanks
When the user opens the application, there is a screen with a button on it, which says "login." The user clicks on the button, and a webview pops up to allow him to log in to the website. After logging in (the app would need to know somehow),
Yo can do this with two separate Activity classes. I would put the WebView in its own Activity. This is easier than managing lots of different View objects yourself. Also, you'll get transitions between different things if you put each part in its own Activity.
You'll can launch the login Activity with the startActivityForResult() method, allowing it to return if the login was successful or not.
If you want to detect the login, you can monitor events in a WebView using a WebViewClient. You set the WebViewClient of your WebView using the setWebViewClient() method.
the webview would disappear,
Simply start the next Activity using an Intent and call the finish() method on your first Activity. If you do this then the use won't come back to login button Activity if they click back as it won't be on the stack any more.
What I'm not clear on is how long the login at the website will be valid for. You may need to set the flags on the Activities in your Manifest, to ensure the user has to log in again if they leave and then return to your application.
and then a list of usernames will pop up. (ListView?)
Use a ListActivity. This is an Activity which comes with the API designed for displaying a single ListView.
When the user clicks on one of the usernames, a webview of the username's profile will pop up. Of course, when the user pushes "back", it goes back to the list of usernames.
So use the onListItemClick() method in ListActivity to detect the touch and launch a new Activity containing the WebView to show the profile. As this is in a new Activity the back handling is all automatic.
Essentially it could all be done within one activity. I can try to easily demonstrate how it could be done.
When you run your app, Activity (AndroidManifest.xml) is called.
View (could be called, main.xml) is shown displaying a login button
Upon clicking the button, you launch your WebView
Successful login, switches the View to a custom view displaying usernames on a ListView (might be a predefined XML file you create named userlist.xml)
Using onClick on a specific username will launch a WebView regarding that specific username.
To return back to your application when the user hits the Back button, you might need to utilize onPause and onResume but I am not sure.
This may not be the best approach, or even a good one, but it might help clear up any confusion.
EDIT:
An Activity is what gets bound to the AndroidManifest.xml as the main entry point into an application. A View contains user interactive components within your Activity, such as a login button, displaying username's, viewing contents on the web (WebView), etc.
First of all I'd consider a different way of approaching this problem.
You could create your own login layout in Andoid and send your login data to the website. After doing this you should create a ListView of all user names. If the user selects one of these user names you should open a WebView.
The problem would be, that you would have to check whether the login was successful or not! Basically you need to do a HttpRequest, parse the output and check it.
If it's your website you want to login you could write a small wrapper for your login which returns true/false for your login. (php wrapper which returns xml or plaintext)
Anyway, if you really want to do the login via WebView you can check it via:
private void initWebView(final WebView mWebView) {
mWebView.setWebViewClient(new WebViewClient() {
public boolean shouldOverrideUrlLoading(WebView view, String url) {
Page = new WebView(YourClass.this);
Page.getSettings().setJavaScriptEnabled(true);
Page.loadUrl(url);
if(url.contains("OkDoLogIn.php")) {
/* Check if login was successful if true start new Activity */
}
return true;
}
});
}
With url.contains("OkDoLogIn.php") you basically check which url is about to open. In your case it would be the url or a part of the url of your login button.
Nevertheless you would have to check if your login was successful or not!
Edit: See 1st comment!