multithreading - Android: Running thread preventing animation from starting -
I currently have an Android activity that manages RSS feed stored locally. In this activity, these feeds are updated in their thread through a private class. I am also trying to include an "update" icon that revolves with a Animation works by itself, but the thread is not running, despite the entry of the code issuing the logs. I suspect that due to the thread is not completely safe, and taking most CPU time, though I would love to know if there is a better way of achieving this. The (I know that Run the executable. Make the following changes. rotate animation , while this thread is going on.
updateAllFeeds () is called a button press Here's the relevant code:
/ ** * Rotation * / Protected rotate animation Animation Properties for GetRotateAnimation () {// log in it now Log.d ("RSS Alarm", "Performing Animation"); Rotate animation animation = new rotation animation (35 9F, 0F, 16F, 21F); Anim.setInterpolator (New LinearInterpolator ()); Anim.setRepeatCount (Animation.INFINITE); Anim.setDuration (700); Return anem; } / ** * Rotates the latest icon * with rotate * / Public Zero Setuping () {btnRefreshAll.startAnimation (getRotateAnimation ()); } / ** * Refresh icon can be reverted back to the image * / public stop-stop updating () {Log D. ("RSA Alarm", "Stop Animation"); BtnRefreshAll.setAnimation (zero); refresh list(); } / ** * All RSS feeds update in the list * / secure void updateAllFeeds () {setUpdating (); Updater updater = new updater (channel); Updater.run (); } / ** * To Update RSS Feeds in a New Thread Class * @ Author Michael * * / Private Class Update Updater {// Mode Flag Static Final Ink MODE_ONE = 0; Public stable ending end MODE_ALL = 1; // Class Vars channel channel; ArrayList & LT; Channel & gt; channel list; Int mode; / ** * Manufacturer * @ Pal channel for the only update * / public updater (channel channel) {this.mode = MODE_ONE; This.channel = Channel; } / ** * To update more than one feed at a time * List of channels / public updaters (altlist & lt; channel & gt; channel list) to update * creator * papara channel list {this .mode = MODE_ALL; This.channelList = channelList; } / ** * Performs all good stuff * / run public zeros () {// flag to write problem flag boolean write_error = false; // If we have a singular or list, check that (if.mode == MODE_ONE) {// update a feed to only one update STATUS = channel.update (getApplicationContext ()); // Check for error if (updateStatus == 2) {// error - write show dialog_error = true; }} And {// (for Iterate via all feeds (Int i = 0; I & lt; this.channelList.size (); i ++) {// Update this item update updateatatus = channelList.get (I) .update (getApplicationContext)); If (updateStatus == 2) {// error - write show dialog_error = true; }}} // If we have any errors, show the dialog if (write_error) {runOnUiThread {public runs zero () {showDialog (ERR_SD_READ_ONLY);}}); } // Update Updater (); } // and run ()} // and class ad
updateStatus == 2 is a bit of bad practice, it's one of the next things One is
Secure void updateAllFeeds () {setUpdating (); New thread (New Updater (Channel)). Start ();}
runOnUiThread block in callUp
private square updater to run {........ ......... ......... general Generic Zero Run () {......... ........ // And Updater RunOnththread (New Runnabal) (Public Wired Run) {stopUpdating ();}}); } // and run ()} // and class updater
Comments
Post a Comment