Update a view on a schedule
I am trying to update my view but a I have a bit problem
I take data from Internet and I want to update the same view with new data every minute.
What is the best way to do this.
As it stands I'm currently trying this timer at the end of my view:
myTimer.schedule(new TimerTask() {
@Override
public void run() {
TimerMethod();
}
private void TimerMethod() {
Csv csv= new Csv(simbol);
csv.readCSV();
ArrayList<Quotes> info = new ArrayList<Quotes>();
info= csv.getListaQuotes();
Intent i = new Intent(getParent(), TabGrupo1.class).putExtra("opc", 2);
i.putExtra("datos", info);
TabGroupActivity parentActivity = (TabGroupActivity)getParent();
parentActivity.startChildActivity("Component", i);
}
}, 0, 1000);
but I obtain this error
07-14 13:23:00.902: ERROR/AndroidRuntime(911): FATAL EXCEPTION: Timer-0
07-14 13:23:00.902: ERROR/AndroidRuntime(911): java.lang.RuntimeException: Unable to instantiate activity ComponentInfo{com.finance/com.finance.TabGrupo1}: java.lang.RuntimeException: Can't create handler inside thread that has not called Looper.prepare()
07-14 13:23:00.902: ERROR/AndroidRuntime(911): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2585)
07-14 13:23:00.902: ERROR/AndroidRuntime(911): at android.app.ActivityThread.startActivityNow(ActivityThread.java:2503)
07-14 13:23:00.902: ERROR/AndroidRuntime(911): at android.app.LocalActivityManager.moveToState(LocalActivityManager.java:127)
07-14 13:23:00.902: ERROR/AndroidRuntime(911): at android.app.Loc开发者_如何学CalActivityManager.startActivity(LocalActivityManager.java:339)
07-14 13:23:00.902: ERROR/AndroidRuntime(911): at com.finance.TabGroupActivity.startChildActivity(TabGroupActivity.java:57)
07-14 13:23:00.902: ERROR/AndroidRuntime(911): at com.finance.Info$1.TimerMethod(Info.java:67)
My Activity is a Group of Activity because I use Tab and show the view in different tab. In this case I want to refresh tab 2, that the same view that is running.
Any ideas or suggestions.
Thanks
You need to use AsyncTask in Android. In AsyncTask mainly three methods 1.onPreexecute() 2.doInBackground() 3.onPost() Refer this Using this you can easily found your solution
This seems like something that could be solved with a Content Provider, Broadcast Receiver, and Service with an alarm. Set the service to run every min with Alarm Manager. Have the service get the new data and sends a broadcast informing the main Activity that there is new information to display. An amazingly good video tutorial on Broadcast Receivers can be found here.
Additionally, the rest of his bootcamp videos piece together a program with very similar functionality.
精彩评论