I open a new thread to talk about my problem :-) , I have problems with communication between "service" to the "Activity"
what I have:
I have a FTP download of a file that is downloaded in the background as a service! In the end I had a time X in a variable.
furthermore it is checked whether the file is also fully load , I make it with a simple comparison of the data size.
So I have a time 0s "start time" 12:22:00 up as 20sec is "end time" 12:22:20
and a download size of 0Kb goes to 5000kb.
These values are defined in the service.
Project:
I want to show this graphically or via text in the GUI of the activity .
like this:
File Download time: X seconds
X seconds, will be scanned progressively and dynamically displayed. 1. sec, 2 sec ...... 20 sec
Download traffic: X kb of 5000 kb
Download rate is to be displayed: 0kb, 250 kb, 500 kb ..... 5000 kb.
Now my question:
how do I do that, which transfers the service these values to the activity!
and how can I display in the activity "dynamically and automatically."
I thank you all for your efforts
Send a broadcast Intent with the data via sendBroadcast(), that the activity picks up with a BroadcastReceiver. Here is a sample project from one of my books demonstrating this.
Consider to make that You want without Service, but with AsyncTask.
You could update UI with current progress using publishProgress(...) method of AsyncTask. No services, no broadcast receivers.
http://developer.android.com/reference/android/os/AsyncTask.html
Related
I'm trying to measure I/O throughput in Android. I tried a simple test by running Androdbench, and sampling /proc/diskstats for /dev/sda every second. But the results dont match.
Androbench tells me that my phone's storage is capable of a maximum 160MB/s sequential write throughput. But when I diff the "sectors written" field of diskstats I find that the disk writes 500 MB/s at one point. Which doesnt make sense. Here are the two strange samples
207808 53404 19437816 332280 230564 26206 49888720 1100720 0 103030 1433600
207808 53404 19437816 332280 230590 26229 50937672 1100900 0 103210 1433780
These should be block layer results, so to my understanding there should be no cache involved. What am I missing?
I have been using std::chrono::steady_clock for interval calculation in an application i am making for Android platform.
Code:
// On application start
auto timeSinceEpoch = std::chrono::steady_clock::now().time_since_epoch();
auto timeInSec = std::chrono::duration_cast<seconds>(timeSinceEpoch).count();
log("On Enter Start Time Point - %lld", timeInSec);
Output:
On Enter Start Time Point - 521
Now i switch off the phone and restart the phone. I run my application and this time Output is:
On Enter Start Time Point - 114
As per definition at cppreference.com
"Class std::chrono::steady_clock represents a monotonic clock. The time points of this clock cannot decrease as physical time moves forward."
How is the output when i restart the phone giving lesser value?
If anyone has faced this issue please help me out here. Thanks!!
The formal requirement for a steady clock is that the result of a call to now() that happens before another call to now() is always less than or equal to the result of the second call. The happens before relationship only applies to actions within a program run. A steady clock is not required to be steady across different invocations of a program.
On Android, AFAICT steady_clock is the same as (from Java) System.Clock.elapsedRealtime, which resets to zero on boot -- https://developer.android.com/reference/android/os/SystemClock.html
I'm totally failing to dig up the source code for clock_gettime, though. https://android.googlesource.com/platform/ndk.git/+/43255f3d58b03cd931d29d1ee4e5144e86e875ce/sources/cxx-stl/llvm-libc++/libcxx/src/chrono.cpp#124 shows it calling clock_gettime(CLOCK_MONOTONIC), but I'm not sure how to penetrate the veil from there.
Well, I'm working on an app that loads images from Internet. Everything is OK so far, but I'd like to know how could I calculate how long such images take to be loaded from Internet?
There is any method on Bitmap to make that? Maybe there is any other way that you would suggest me?
Cheers,
Well if you know the filesize b of the image (in bytes), and the speed s at which it's downloading (in bytes per second), then the time t (in seconds) to download the file will be:
t = b / s
Simple math really to convert your units as needed. Don't forget that this value is constantly changing as the download speed changes.
Edit: Now if you're only looking to calculate how long the image took to download and maybe display this information after the fact, then a simple solution would be to start a timer when the download is initiated and stop it when it's done.
HTTP response will contain a Content-Length field this will let you know how much is to be downloaded. If you know the speed of your conection then you can work out the estimated time using time = dataSize / downloadSpeed.
You can also use the knowlege of how much you have downloaded so far to work out how long it will take using linear extrapolation. time = (dataSize * (timeNow - timeStart)) / dataDownloadedNow
So i overclocked my phone to 1.664ghz and I know there are apps that test your phone's CPU performance and stressers but I would like to make my own someway. What is the best way to really make your CPU work? I was thinking just making a for loop do 1 million iterations of doing some time-consuming math...but that did not work becuase my phone did it in a few milliseconds i think...i tried trillions of iterations...the app froze but my task manager did not show the cpu even being used by the app. Usually stress test apps show up as red and say cpu:85% ram: 10mb ...So how can i really make my processor seriously think?
To compile a regex string:
Pattern p1 = Pattern.compile("a*b"); // a simple regex
// slightly more complex regex: an attempt at validating email addresses
Pattern p2 = Pattern.compile("[a-z0-9!#$%&'*+/=?^_`{|}~-]+(?:\.[a-z0-9!#$%&'*+/=?^_`{|}~-]+)*#(?:[a-z0-9](?:[a-z0-9-]*[a-z0-9])?\.)+(?:[A-Z]{2}|com|org|net|edu|gov|mil|biz|info|mobi|name|aero|asia|jobs|museum)\b");
You need to launch these in background threads:
class RegexThread extends Thread {
RegexThread() {
// Create a new, second thread
super("Regex Thread");
start(); // Start the thread
}
// This is the entry point for the second thread.
public void run() {
while(true) {
Pattern p = Pattern.compile("[a-z0-9!#$%&'*+/=?^_`{|}~-]+(?:\.[a-z0-9!#$%&'*+/=?^_`{|}~-]+)*#(?:[a-z0-9](?:[a-z0-9-]*[a-z0-9])?\.)+(?:[A-Z]{2}|com|org|net|edu|gov|mil|biz|info|mobi|name|aero|asia|jobs|museum)\b");
}
}
}
class CPUStresser {
public static void main(String args[]) {
static int NUM_THREADS = 10, RUNNING_TIME = 120; // run 10 threads for 120s
for(int i = 0; i < NUM_THREADS; ++i) {
new RegexThread(); // create a new thread
}
Thread.sleep(1000 * RUNNING_TIME);
}
}
(above code appropriated from here)
See how that goes.
I would suggest a slightly different test, it is not a simple mathematical algorithms and functions. There are plenty of odd-looking tests whose results always contains all reviews. You launch the application, it works for a while, and then gives you the result in standard scores. The more points more (or less), it is considered that the device better. But that the comparison results mean in real life, is not always clear. And not all.
Regard to mathematics, the first thing that comes to mind is a massive amount of counting decimal places and the task to count the number "pi"
OK. No problem, we will do it:
Here's a test number one - "The Number Pi" - how long it takes your phone to calculate the ten million digits of Pi (3.14) (if someone said this phrase a hundred years ago, exactly would be immediately went to a psychiatric hospital)
When you feel that the phone is slow. You turn / twist interface. But how to measure it - it is unclear.
Angry Birds run on different devices at different times - perhaps test "Angry Birds"
We think further - get a couple more tests, "heavy book" and "a large page."
algorithm of calculation:
Test "of Pi"
Take the Speed Pi.
Count ten million marks by using a slow algorithm "Abraham Sharp Series. Repeat measurements several times, take the average.
Test "Angry Birds"
Take the very first Angry Birds (not required, but these versions are not the most optimized)
Measure the time from launch to the first sounds of music. Exit. Immediately run over and over again. Repeat several times and take the average.
Test "Large Page"
Measure the load time of heavy site pages. You can do it with your favorite browser :)
You can use This link (sorry for the Cyrillic)
This page is maintained by using "computers browser" along with pictures. Total turns out 6.5 Mb and 99 files (I'm still on this page in its stored version of a small sound file)
All 99 files upload to the phone. Turn off Wi-Fi and mobile Internet (this is important!)
Page opens with your browser. Click the "back" button. And now click "Forward" and measure the time the page is fully loaded. And so a few times. Back-forward, backward-forward. As usual, we take the average.
All results are given in seconds.
During testing all devices that support microSD cards, was one and the same card-Transcend 16 Gb, class 10. And all data on it.
Well, the actual results of the tests for some devices TEST RESULT
https://play.google.com/store/apps/details?id=xcom.saplin.xOPS - the app crunches numbers (integer and float) on multiple threads (2x number of cores) and builds performance and CPU temperature graphs.
https://github.com/maxim-saplin/xOPS-Console/blob/master/Saplin.xOPS/Compute.cs - that's the core of the app
I am creating a program which requires me to change a setting in the program when the video reaches specific points (at 1/3 of the video's completion, 2/3's and on completion). Android has a built in callback method for completion so performing an action at that point in time is not difficult. However, I don't know how to go about checking when the video has reached 1/3 and 2/3's of completion.
Using a MediaPlayer control you will get
the total duration of your media file in milliseconds:
myMediaPlayer.getDuration()
you will implement a thread that check every second for the current position at 1/3, 2/3 and 3/3 of the videos completion, with
myMediaPlayer.getCurrentPosition(); //***current Position in milliseconds.