runnable

Android Java: Update seekbar to show progress as audio file plays

落爺英雄遲暮 提交于 2019-12-12 10:24:53
问题 This is my first Android/Java app. I am using the first answer here to try to initiate a repeating task, updating a seekbar ("timeSlider") to show progress as an audio file plays. Here is my code (eliminating a few irrelevant lines): private int timeSliderInterval = 1000; // 1 second private Handler timeSliderHandler; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_play); Intent intent = getIntent(); Runnable

Runnable jar runs too slow compared to eclipse project

雨燕双飞 提交于 2019-12-12 08:55:25
问题 I have extracted a jar file from an eclipse project but it runs too slow. It takes almost twenty minutes to complete and the eclipse project only takes some seconds. I exported runnable jar with library handling with all three differenct choices. I also exported jar file with all library handling choices. I also run jar file with command: java -Xmx2048m -Xms1024m -jar "finalJar.jar" I have removed all System.out.println except the last one that gives me the answer. What can I do to export a

Inconsistent messaging between handler and runnable

此生再无相见时 提交于 2019-12-12 05:34:43
问题 I'm trying to update UI from a background thread through a Handler. Runnable sends periodically (minimum once every two seconds, maximum 16 times per second) new data to handler to be updated. On my runnable class I have a flag for starting/stoping loop -there are methods on main class attached to buttons for this task-. I have several problems with this: First message received is always 0 After a few loops, message received by handler is always 0 From time to time (sorry, poor precision, I

handler.removecallbacks not working

痞子三分冷 提交于 2019-12-12 02:07:52
问题 public class MainActivity extends AppCompatActivity { int total = 0,k=0,j=0,i; public EditText editText; private int mInterval = 1000; Handler mHandler = new Handler(); String formula_value,url_value; TextView textView,textView1; ArrayList<Integer> list; JSONArray m_jArry,m_jArry1; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar); setSupportActionBar

Animating 3 parts of a view

别来无恙 提交于 2019-12-12 02:05:18
问题 I am trying to make an app view that, when presented with a subtraction problem, will show an animation of a growing rectangle (or fat line) that crawls up the number line to that integer. I already have things set up so that I click "show me!" and bars are drawn along the number line showing the minuend, the subtrahend and the difference, but I'd like to be able to have a positive number's rectangle crawl up in a positive direction, negative from zero in the negative direction. In looking

Counting a single variable in multiple threads

三世轮回 提交于 2019-12-11 23:11:34
问题 I've got the following runnable class. public class OnesRun implements Runnable { public int ones = 0; private int passendNumber; public OnesRun(int passendNumber) { this.passendNumber = passendNumber; } public void run() { if (passendNumber == 1) ones++; } } Every instance of this class should increase the value of ones if it encounters a one. After all threads have been executed I want to read the value of ones from outside the class. How can I increment ones thread-safe ? How can I access

How do you make a new thread in java with opengl support?

北慕城南 提交于 2019-12-11 18:34:51
问题 I'm making a new 3D java game with lwjgl, and everything's going along great, but I'm trying to create some 3D objects in a different thread, like so: new Thread(new Runnable() { @Override public void run() { for(int x = 1; x < 5; x++) { for(int z = 1; z < 5; z++) { Object3D curObject = game.createGrassBlock(game.maps.get(0)); curObject.setPosition(x, curObject.getSize().getY() / 2, z); curObject.defaultPosition = curObject.getPosition(); Thread.sleep(1); } } } }).start(); However, whenever I

Unable to understand the working of Threads- Runnable Interface

若如初见. 提交于 2019-12-11 18:10:14
问题 public class Test { private static void funct(final int i) { new Thread(new Runnable() { public void run() {System.out.println(i);} }).start(); } public static void main(String[] args) { System.out.println(1); funct (2); System.out.println(3); funct (4); System.out.println(5); } } Every time I run it, I am getting one of the below solutions. Why so? 1 3 5 4 2 1 3 5 2 4 1 3 2 5 4 回答1: The order at which the numbers will be printed out is indeterminate in this example. The only thing you know

CompletableFuture: several tasks

三世轮回 提交于 2019-12-11 16:43:06
问题 How can I asynchronously execute 20 Runnable tasks(or 1 task 20 times), using 5 CompletableFutures? That's what I've got: Runnable task = () -> { long startTime = System.currentTimeMillis(); Random random = new Random(); while (System.currentTimeMillis() - startTime < 3000) { DoubleStream.generate(() -> random.nextDouble()) .limit(random.nextInt(100)) .map(n -> Math.cos(n)) .sum(); } System.out.println("Done"); }; for (int i = 0; i < 4; i++) { CompletableFuture<Void> future1 =

Why does my treeview in GUI with QFileSystemModel sometimes freezing when I copying file in separate thread (Qt)?

做~自己de王妃 提交于 2019-12-11 16:12:12
问题 Here is my Model, that inherits QFileSystemModel class MyFileSysModel : public QFileSystemModel { Q_OBJECT public: MyFileSysModel( QObject *parent = 0); Qt::ItemFlags flags(const QModelIndex &index) const; bool dropMimeData(const QMimeData *data, Qt::DropActions supportedDropActions() const; }; in MainWindow I created model and initializied treeview MainWindow::MainWindow(QWidget *parent) : QMainWindow(parent), ui(new Ui::MainWindow) { ui->setupUi(this); model = new MyFileSysModel(this);