runnable

Start new activity in window manager

淺唱寂寞╮ 提交于 2019-12-11 13:19:30
问题 I want to start a new activity, the activity plays a live stream from a source. When I start the activity, it plays the content on the whole screen. I want to display the contents of the stream in a small screen which is a surfaceview. I am doing this by using a handler which runs a runnable and so on. This is how I am doing it: //new activity played from here Intent localIntent3 = new Intent("android.intent.action.MAIN"); //intent flag set to start a new task over the previous one

How to make a Runnable Change a given value

别说谁变了你拦得住时间么 提交于 2019-12-11 12:36:12
问题 So the problem I am currently facing is that I want to write a method, that creates a runnable that changes a given Value; in this case it's a Boolean Object. (I use this, to make it possible to react on different ways to a Key Press) If I am just using a Method of the passed Object it works just fine. However: public static Runnable createOnOffSwitchRunnable(Boolean b) { final Boolean Reference = b; Runnable R = new Runnable() { public void run() { if (Reference.booleanValue() == true) {

How to know when a thread stops or is stopped?

我是研究僧i 提交于 2019-12-11 12:34:21
问题 I have the next code: Executor exe = Executors.newFixedThreadPool(20); while (true) { try { exe.execute(new DispatcherThread(serverSocket.accept())); continue; } catch (SocketException sExcp) { System.exit(-1); } catch (Exception excp) { System.exit(-1); } } For each DispatcherThread I create a connection to the database (it means I have 20 connections), what I need to know is how I can close the connection to the database when the thread is stopped or it stops or finishes its flow. 回答1: You

KeyListener not responding to keyboard input

怎甘沉沦 提交于 2019-12-11 12:29:36
问题 I've been trying to learn more advanced java on my own (My class is only covering text files) and I'm stumped on the using KeyListener. I managed to get it to work in another program, but I can't find the problem here. No errors show up on the console. This program uses a robot to type predefined Strings in a text file. Here's the main class. import java.awt.AWTException; import java.awt.event.KeyEvent; import java.awt.event.KeyListener; import java.io.File; import java.io

How to make a Button blink in Android?

本小妞迷上赌 提交于 2019-12-11 07:19:02
问题 If the user (in my quizgame) chooses the false answer, the button with the correct answer should blink green. So far i did it like this: if(answerTrue) for (int i = 0; i < 2000; i = i + 250) { handler.postDelayed(rbl_blinkNormal, i); i = i + 250; handler.postDelayed(rbl_blinkGreen, i); } And the runnables: Green: rbl_blinkGreen= new Runnable() { @Override public void run() { btn_richtig.setBackgroundResource(R.drawable.color_green_btn); } }; Normal: rbl_blinkNormal= new Runnable() { @Override

Android Runnable runs faster after Resume

本小妞迷上赌 提交于 2019-12-11 06:26:47
问题 Scenario I have a runnable that outputs a the value of a variable every 1 second. The runnable starts when I start the mainActivity and runs throughout the app in the background. Problem When I close the app (hidden state) and start the app again, the logcat starts outputting faster. It goes faster everytime I do this. Why ? @Override public void onStart() { mHandler.postDelayed(myRunnable, 1000); super.onStart(); } public Runnable myRunnable = new Runnable() { @Override public void run() {

Running multiple threads in Java

泄露秘密 提交于 2019-12-11 06:23:01
问题 I'm having a very weird problem.I'm working on an assignment that involves building a simulation of figures moving on a 2d "chessboard". Each figure is represented by an object implementing the Runnable interface. The problem is that when I attempt to run each object in a different thread like so: ArrayList< Thread > playerThreads = new ArrayList< Thread >(); ArrayList< Player > players = p.getSpawnedPlayers(); // This method returns all Runnable objects for ( Player pl : players )

Read text file that is not in the main package in a runnable jar

空扰寡人 提交于 2019-12-11 00:50:02
问题 I have a Swing Java program that reads *.txt files in a resource folder called 'res' containing subfolders of different kind of JSONs. When I run directly from Eclipse, all is fine. If I create an executable jar it doesn't work. I managed to make it work with an horrifying solution, putting all my text files in the package where they are called. To read them I use this line of code: InputStream is = this.getClass().getResourceAsStream(file + ".txt"); where file is a string. I thought this

Android Listview item Change after 10 seconds automatically?

◇◆丶佛笑我妖孽 提交于 2019-12-10 19:08:56
问题 i have two arraylist one is departurelist and one is arrival list i want to show this list alternatively means after 10 seconds list is change automatically first 10 seconds departure list and next 10 second arrival list i will put my code here i will try usint runnable but my apps is hang when run this code Home activity.java final int []sliderImageArray={R.drawable.banner,R.drawable.banner01,R.drawable.banner02}; final int []footerImageArray={R.drawable.bottomadv,R.drawable.sandwich,R

Communication between UI thread and other threads using handler

别说谁变了你拦得住时间么 提交于 2019-12-10 14:56:42
问题 How to do inter thread communication between UI thread and background thread? I want use common handler concept here to update my UI. I have the concept as below new Thread(new Runnable() { public void run() { while (mProgressStatus < 100) { mProgressStatus = doWork(); // Update the progress bar mHandler.post(new Runnable() { public void run() { mProgress.setProgress(mProgressStatus); } }); } } }).start(); I want to use two classes, one class contains main thread, another class contains