Android, if/else construct always fails (Compiler fails to read changes) - android

What i'm trying to do should be pretty simple, i'm calling an IntentService to check periodically in background if the current time is before or after a specified time (passed as Extras in the intent from the MainActivity) and get a notification when it happens.
In Thread's run() method i get an instance of the current time and use it as comparison to the previously specified one in an if/else construct, before re-running the Thread.
The problem is that it always go for "else" even if the current time is after the other one. This problem is just too strange, can anyone explain me where is the error?
Here is my IntentService class:
public class MyCheck extends IntentService {
int hour = 0; int minute = 0;
int i = 0;
private static final String TAG = "Check";
int hourNow;
int minuteNow;
Handler handler = new Handler();
public MyCheck() {
super(MyCheck.class.getName());
}
#Override
protected void onHandleIntent(Intent intent) {
Log.w(TAG, "Service Started!");
hour = intent.getIntExtra("hour", 0);
minute = intent.getIntExtra("minute", 0);
Log.w(TAG, "Step 1 ");
Thread runnable = new Thread() {
#Override
public void run() {
/* do what you need to do */
Log.w(TAG, "Step 2 ");
/* get current time */
Calendar c = Calendar.getInstance();
hourNow = c.get(Calendar.HOUR);
minuteNow = c.get(Calendar.MINUTE);
//HERE, IT SEEMS THAT IT'S ALWAYS BEFORE hour AND minute
if(hourNow > hour || (hourNow == hour && minuteNow > minute)) {
//SEND
Log.w(TAG, "RUN ");
Intent broadcast = new Intent();
broadcast.setAction(NOTIFICATION_SERVICE);
sendBroadcast(broadcast);
handler.removeCallbacks(this);
}
else {
//NOTHING
i++;
Log.w(TAG, "NOT YET " + i);
}
//REPEAT EVERY 6 SECONDS
try {
sleep(6000);
handler.post(this);
} catch (InterruptedException e) {
e.printStackTrace();
}
}
};
runnable.start();
}
}
EDIT
I've found the trivial problem as you can see in my answer below.
If someone wants to complete the answer with some more information about the problems that can occur during the building process they will be apreciated. TIA

The simple solution to this was to wait and reboot Windows. The code wasn't flawed after all, it's just something on the building process that needed some time to tell the compiler that the error wasn't there: maybe there was a copy in cache of a past error that was still taken in account, i'm not sure.
Maybe you can add some information to my last statement, posting an answer or a commenting about it.

Related

Is there a way to get the location every x minutes, even when there are no changes?

I am using Android Studio. I use locationManager.requestLocationUpdates(...) to get the location.
I want to do something like this:
//print location every 5 minutes
12:10am lat=10.23652 long=21.25441
12:15am lat=10.23652 long=21.25441
12:20am lat=15.21456 long=58.21452
12:25am lat=12.24752 long=27.24587
12:30am lat=12.24752 long=27.24587
12:35am lat=12.24752 long=27.24587
...
I'm not interested in knowing if the location changed, I just want to print it every x minutes.
A solution could incorporate a Handler with a postDelayed. It is important to remove any Callbacks!
Try something like this:
private boolean continueLoop = true;
private Handler myHandler = new Handler();
private void startLocationManager() {
try{
Log.d(TAG, "startLocationManager - Started");
// here the delay (in this example it is effectively the interval)
int minutes = 5;
int delay = 1000 * 60 * minutes;
myHandler.postDelayed(mAutoLocationManager, delay);
}
catch(Exception ex){
Log.e(TAG, ex.getMessage());
}
}
private Runnable mAutoLocationManager = new Runnable() {
public void run() {
if(continueLoop){
// preform the scan for the location coordinates
startYourLocationCoordinates();
//re-trigger the call to start a new interval
startLocationManager();
{
}
};
// Make certain that you remove the callback when you leave the activity -- maybe in onPause()
private void stopAutoDownloadManager(){
try{
myHandler.removeCallbacks(mAutoLocationManager);
}
catch(Exception ex){
Log.e(TAG, ex.getMessage());
}
}

File Modification check on Android

I have written a loop that checks the file modification date on two files.
This is successful as far as the Toast text is concerned.
However I cannot seem to work out the syntax to actually compare the dates, comparing Date1 > Date2 is actually rejected by android studio.
Lots of advice on how to get the most recent modification date is on Stack Overflow, just not the answer as to how to craft the necessary if statement.
Any help would be most appreciated. (yes I have read documentation! Usage examples poor on this subject)
Handler mHandler = new Handler();
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
// Email sync loop (maybe change for watcher method)
new Thread(new Runnable() {
#Override
public void run() {
while (true) {
try {
Thread.sleep(10000);
mHandler.post(new Runnable() {
#Override
public void run() {
Toast.makeText(MainActivity.this, "Loop", Toast.LENGTH_SHORT).show();
File file = new File(String.valueOf(Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_DOWNLOADS + "/Database1.db")));
if (file.exists()) {
Date lastModified = new Date(file.lastModified());
String modified = lastModified.toString();
Toast.makeText(MainActivity.this, modified, Toast.LENGTH_LONG).show();
}
File file2 = new File(String.valueOf(Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_DOWNLOADS + "/Database2.db")));
if (file2.exists()) {
Date lastModified2 = new Date(file2.lastModified());
String modified2 = lastModified2.toString();
Toast.makeText(MainActivity.this, modified2, Toast.LENGTH_LONG).show();
}
}
});
} catch (Exception e) {
// TODO: handle exception
}
}
}
}).start();
}
You don't need the separate thread, the loop and the sleep() call, you can simply schedule the check on the Handler instance using postDelayed() method. It will be executed on the main thread which is perfectly fine for you and won't block the app. As a final step in your Runnable instance you can schedule it again, so it will run in a loop.
If you want to stop it then call removeCallbacksAndMessages(null) on the handler.
I am not sure what do you want to achieve with this, but maybe instead of doing a polling loop you can use FileObserver class for monitoring file changes, here is an example how to use it.
For comparing two dates you can always compare their millisecond values.
For e.g. date1.getTime() > date2.getTime()
getTime() method returns the time in milliseconds and it is a long value that can be easily compared.

Circle Progress Bar on Fragment is not showing progress

I'm trying to show feedback the percentage of which they have downloaded data from a server.
The flow goes something like this:
LoginActivity
- onSuccess, call Service to download data
- while Service is working, I've already switched the user to HomeActivity
HomeActivity
-This activities layout holds a Fragment I created called LoadingFragment
-There is a method in LoadingFragment that is subscribed to an event that is posted by the Service
My problem is that the Fragment UI is not changing at all whenever an event has been posted.
I logged everything, and I can see the event posting the correct data but the data is not being reflected on the UI.
Below is my Service:
#Override
public int onStartCommand(Intent intent, int flags, final int startId) {
Integer id = intent.getIntExtra("id", 0);
//do sync here
Log.i(LOG_TAG, "Make rest call to retrieve all r for id: " + id);
mRestClient.getApiService().getR(id, new Callback<List<R>>() {
#Override
public void success(List<R> rResponse, Response response) {
Integer outstanding = routeResponse.size();
Integer percentage;
LoadingEvent loadingEvent = new LoadingEvent();
SyncEvent syncEvent = new SyncEvent();
Log.i(LOG_TAG, "Callback success r");
System.out.println("yohellotest");
Log.i(LOG_TAG, "Begin insertion");
DaoMaster daoMaster = MyApp.getDaoMaster();
DaoSession session = daoMaster.newSession();
SQLiteDatabase db = session.getDatabase();
RDao rDao = session.getRDao();
WDao wDao = session.getWDao();
JDao jDao = session.getJDao();
Log.i(LOG_TAG, "--Beginning Transaction--");
//db.beginTransaction();
try {
int counter = 0;
for(int i = 0; i < rResponse.size(); i++) {
R r = rResponse.get(i);
rDao.insert(r);
Log.i(LOG_TAG, "inserted r: " + r.getId());
for(int j = 0; j < r.getW().size(); j++) {
W w = r.getW().get(j);
wDao.insert(w);
Log.i(LOG_TAG, "inserted w: " + w.getId());
for(int k = 0; k < w.getJ().size(); k++) {
J j = w.getJ().get(k);
jDao.insert(j);
Log.i(LOG_TAG, "inserted j: " + j.getJId());
}
}
counter += 1;
percentage = (int) Math.floor((double) counter / outstanding * 100);
loadingEvent.setPercentage(percentage);
bus.post(loadingEvent);
}
Log.i(LOG_TAG, "Finished inserting");
//db.setTransactionSuccessful();
} catch (Exception e) {
Log.i(LOG_TAG, "Exception happened " + e.getMessage().toString());
System.out.println("yo something happened, but I don't know what");
} finally {
Log.i(LOG_TAG, "--Closing transaction--");
//db.endTransaction();
}
syncEvent.setIsSuccess(true);
syncEvent.setStatus(200);
bus.post(syncEvent);
}
#Override
public void failure(RetrofitError error) {
Log.i(LOG_TAG, "Rest call failed for this api");
System.out.println("failtests");
}
});
return START_STICKY;
}
Fragment Subscribed Method
#Subscribe
public void loadingResponse(final LoadingEvent loadingEvent) {
Log.i(LOG_TAG, "Response from loading: " + loadingEvent.getPercentage());
if(getActivity() == null)
return;
textTest.setText(loadingEvent.getPercentage().toString());
getActivity().runOnUiThread(new Runnable() {
#Override
public void run() {
Log.i(LOG_TAG, "Updating ui for loading text" + loadingEvent.getPercentage().toString());
mCircularProgressBar.setProgress(loadingEvent.getPercentage());
textTest.setText(loadingEvent.getPercentage().toString());
}
});
}
When I check my Logs, I see everything coming in fine, but the UI is not reflecting it. What am I missing here?
EDIT
Forgot to mention. I'm using this library for my circle progress bar:
CircleProgressBar
EDIT
As of today, I still have yet to figure this out. I also noticed that my adapter is not being updated when the service posts the event. Previously, the context used to startService() was the getApplicationContext() from the LoginActivity. I thought this might have been a problem so I changed it to get the instance of the HomeActivity instead. I thought that firing the service from my HomeActivity would have solved the problem, but I'm still getting the same results unfortunately.
Okay so no one really tried to attempt answering my question but I figured it out.
I actually skimped over the documentation part of the Service class and didn't know that it was executing on the Main Thread. To fix this, I had to run an AsyncTask to execute my operation in the background.
The only thing I had to change in my codebase was to move the executing code from the onStartCommand method into an AsyncTask. The AsyncTask will be initiated onStartCommand and everything should be working fine.
My code looks something like this now :
Service
#Override
public int onStartCommand(Intent intent, int flags, int startId) {
DownloadTask downloadTask = new DownloadTask();
downloadTask.execute();
return START_STICKY;
}
private class DownloadTask extends AsyncTask<Void, Void, LoginEvent> {
#Override
protected LoginEvent doInBackground(Void... params) {
//Code here to run my operations
//Call api, insert to db, post events etc...
//
}
#Override
protected void onPostExecute(LoginEvent event) {
//run anything here you want to do after execution
}
}
You can ignore my LoginEvent as this was something for my event bus to post events to any subscribers.
Also, keep in mind that if you are going to change any views from this AsyncTask through the bus, make sure the subscriber uses the runOnUi to execute or else you'll hit a runtime exception since you're trying to change a view from something other than the MainThread.

Timer not working in app

I have written schedule task by using timer. It is working fine withing single activity.But when i am going to another activity it is not working.My intention is to send data to the server some particular time interval. I am giving the code snippet. I am sorry for the format.
private void login()
{
try {
EditText userNameET = (EditText)findViewById(R.id.userName);
EditText passwordET = (EditText)findViewById(R.id.password);
String userName = userNameET.getText().toString();
String password = passwordET.getText().toString();
boolean isLoginOK = isValidUser(userName, password);
String autoSynchStrVal = "";
String autoSyncFreqStr = "";
long autoSyncFreqInMiliSec = 3600000; // default 1 hrs
if (isLoginOK) {
//added by anirban
CommonUtils.IS_NEW_VERSION_AVAILABLE = isNewVersionAvailable();
CommonUtils.IS_NEW_Notification_AVAILABLE = isNewNotificationAvailable();
autoSynchStrVal = CommonUtils.getPolicyValue(appInstance, "IS_MOBI_AUTO_SYNCH_REQ", 0, 0);
if(autoSynchStrVal != null && !"".equals(autoSynchStrVal) && "1".equals(autoSynchStrVal)){
//boolean isAllTransactionsUploaded = false;
// boolean isAllTransactionsUploaded = VersionCheckingActivity.isAllTransactionsUploaded();
// boolean isMobiEligibleForAutoSync = UploadDownload.isMobiEligibleForAutoSync(appInstance ,isAllTransactionsUploaded);
// if(isMobiEligibleForAutoSync){
autoSyncFreqStr = CommonUtils.getPolicyValue(appInstance, "MOBI_AUTO_SYNCH_FREQUENCY", 0, 0);
if(autoSyncFreqStr != null && !"".equals(autoSyncFreqStr)){
autoSyncFreqInMiliSec = (long) (Double.valueOf(autoSyncFreqStr) * 60 * 60 * 1000); // in millisecond
}
/* boolean isMobiEligibleForAutoSync = false;
try {
isMobiEligibleForAutoSync = UploadDownload.isMobiEligibleForAutoSync(appInstance ,
VersionCheckingActivity.isAllTransactionsUploaded());
if(isMobiEligibleForAutoSync){
_doSynch();
}
} catch (UDBAccessException e) {
e.printStackTrace();
} */
myTimer = new Timer();
myTimer.schedule(new TimerTask() {
#Override
public void run() {
ULoginActivity.this.runOnUiThread(new Runnable() {
#Override
public void run() {
// here we are checking again for eligibility for auto synch
boolean isMobiEligibleForAutoSync = false;
try {
isMobiEligibleForAutoSync = UploadDownload.isMobiEligibleForAutoSync(appInstance ,
VersionCheckingActivity.isAllTransactionsUploaded());
Log.d("inside Run : ", "before Synch");
if(isMobiEligibleForAutoSync){
_doSynch();
Log.d("inside Run : ", "after Synch");
}
} catch (UDBAccessException e) {
e.printStackTrace();
}
}
});
}
}, 1000, autoSyncFreqInMiliSec); //here interval is autoSyncFreqInMiliSec
}
endAction(RESULT_LOGIN_OK, null); // it will finish the activity
} else {
// showing login error
TextView login_msg = (TextView)findViewById(R.id.login_screen_msg);
login_msg.setTextAppearance(this, R.style.error_msg);
//login_msg.setTextColor(Color.RED);
login_msg.setText("Login failed.");
}
} catch (UDBAccessException e) {
UUIHandlers.showErrorMessage(this, e.getMessage());
}catch (Exception e) {
UUIHandlers.showErrorMessage(this, e.getMessage());
}
}
To make it work when you leave the current activity, you have to run that code of snippet on the background service.
As you are executing on the current Activity it runs the code for the first time, but as you leave the activity the code wont be triggered itself unless it is registered to a background service.
Here and here you have examples on how to use them
If you want to execute something after some time, even when your activity is not currently in the foreground, you can use the AlarmManager.
Note: The Alarm Manager is intended for cases where you want to have your application code run at a specific time, even if your application is not currently running. For normal timing operations (ticks, timeouts, etc) it is easier and much more efficient to use Handler.
If you want to periodically send information to a server, I suggest you use a Service or an IntentService.
A Service is an application component representing either an application's desire to perform a longer-running operation while not interacting with the user or to supply functionality for other applications to use.
You can find a good example using a LocalService also here.
Finally got the solution .
Now from Async task( different thread), You are trying to insert data in the database which is locked by UI thread. This will throw an exception because the first write has a lock on the db.
If you hold your timer in a field of your activity (Activity subclass) it will probably go away once you launch another activity. Consider moving your timer to service (Service subclass). This will hold your timer going regardless of your activity flow.
Read this for reference about services:
https://developer.android.com/guide/components/services.html

If I finish an activity and call it again, it's attribute values still remain inside thread (RunOnUiThread)

In this case, I have 2 activities. I'm on Activity 1 and go to Activity 2. The application works as intended.
The problem starts when I go back to Activity 1, and start Activity 2 again.
See code below:
public class ScreenWActivity extends SerialComActivity {
private static final String tag = "ScreenWActivity";
private TextView mReception, m_tvDate, mtvPesoPercent, mtvState;
public String mCommand = null;
public int mActualProcess, mNextProcess;
private Commands mLastCommand;
public SettingsGlobal mSettings;
public int mAttempts = 0;
public long mStartTime, mTimeout;
#Override
protected void onCreate(Bundle savedInstanceState) {
// TODO Auto-generated method stub
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_W);
this.mSettings = new SettingsGlobal(this); // get global settings
this.mtvState = (TextView) findViewById(R.id.tv_state); // label to update the current state
startSerialConnection(); // open serial port and start connection. inherited from SerialComActivity (the upper class)
this.mTimeout = 10; // timeout for commands response in seconds
this.mNextProcess = 1; // the next step in the process, its updated in the stepN() methods
this.mActualProcess = 1; // current step in the processo
this.mLastCommand = Commands.OPEN_DOOR; // the last command I've sent, to know what to expect in return
this.executeWorkflow(mNextProcess); // starts the workflow
}
private void step1(){
this.mtvState.setText("Closing door."); // update status
this.writeSerial(Commands.OPEN_DOOR.command("080").getBytes()); // sends the command to the outputstream, the external device reads the command, execute it and respond back
this.mNextProcess = 2; // the next step in the process is 2
this.mActualProcess = 1; // just tracking
this.mLastCommand = Commands.OPEN_DOOR;
startCounting(); // starts the timout, I've sent the command, now I wait for an answer
}
private void step2(){
this.mtvState.setText("Testando peso das balanças 1.");
this.writeSerial(Commands.GET_W.command().getBytes()); // get weight from weighing-machine
mLastCommand = Commands.GET_W; // the last command i sent i requested the weight - now I know what to expect
mNextProcess = 3; // next step in the sequence in case everything goes according to plan
this.mActualProcess = 2; // tracking
startCounting(); // starting timeout to get an answer
}
private void step3(){...}
private void step4(){...}
private void step5(){...}
private void step6(){...}
#Override
protected void writeSerial(byte[] buffer){...}
public void startCounting(){
mStartTime = System.currentTimeMillis();
timerHandler.postDelayed(timerRunnable, 0);
}
public void stopCounting(){
timerHandler.removeCallbacks(timerRunnable);
}
#Override
protected void onDestroy() {
// TODO Auto-generated method stub
stopCounting();
timerRunnable = null;
if(this.mSerialPort != null)
this.mSerialPort.close();
this.mSerialPort = null;
if(AppConfig.DEBUG) Log.i(tag, "finishing!");
finish();
super.onDestroy();
}
public void executeWorkflow(int step) {
switch(step){
case 1:
step1();
break;
case 2:
step2();
break;
case 3:
step3();
break;
case 4:
step4();
break;
case 5:
step5();
break;
case 6:
step6();
break;
}
}
protected boolean validateReturn(String resposta) {
/// we check the command we've sent and the response we're given. if it matches, then we return true, else false
}
// overrided from SerialComActivity, called when the external equipment sends a message to us
// ITS CALLED WHEN THERE IS INPUT FROM THE EXTERNAL EQUIPMENT
#Override
protected void onDataReceived(final byte[] buffer, final int size) {
runOnUiThread(new Runnable() {
public void run() {
stopCounting(); // we remove the callbacks from the timeout thread
if( validateReturn(new String(buffer, 0, size).trim()) ){ // we check if the response is good
executeWorkflow(mNextProcess); // if its good, we move to the next step
}else{
mtvState.setText("invalid return"); // if not we message the user
executeWorkflow(mActualProcess); // we try again
}
}
});
}
// RESPONSIBLE FOR THE TIMEOUT
// the code below was created intending to implement a timeout timer for waiting a response from the external device
Handler timerHandler = new Handler();
Runnable timerRunnable = new Runnable() {
#Override
public void run() {
long millis = System.currentTimeMillis() - mStartTime;
long seconds = (millis / 1000);
timerHandler.postDelayed(this, 500);
if(mTimeout - seconds == 0 ){
mAttempts += 1;
if(mAttempts == 3){ // we make 3 attempts to get a response, if it is the third, we quit trying and give error
mAttempts = 0;
mtvState.setText("Could not communicate.");
stopCounting(); // we end the timer
}else{
executeWorkflow(mActualProcess); // if we can still try, we send the command again
}
}
}
};
}
Inside the method onDataReceived(), which is called everytime I get a response from the external equipment, I use the attribute mLastCommand (which indicates the last command I've sent), so this way I know how to validate the response I get.
When I go back to Activity 2, in the class scope the values of the attributes are the same as the ones I've defined in the onCreate() method. In the LogCat I saw that the attributes values are correctly defined as stated in OnCreate.
BUT, when the method onDataReceived (it's inside a Thread in the SerialComActivity class) is called (which is called when I get data from outside) the value of this same attribute mLastCommand is the same as the first time I started the activity, regardless of the value I define for it. As if the the runnable inside RunOnUiThread is still holding the old values from the first time I entered the activity, and outside of it the class has the values I have defined.
It's like having two different attributes with the same name in the ScreenWActivity.
I tried nulling the attributes inside the onDestroy() method, but to no avail.
Below is the code for the SerialComActivity class:
public abstract class SerialComActivity extends Activity{
SerialPort mSerialPort = null;
protected OutputStream mOutputStream;
protected InputStream mInputStream;
protected ReadThread mReadThread;
private class ReadThread extends Thread {
#Override
public void run() {
super.run();
while(!isInterrupted()) {
int size;
try {
byte[] buffer = new byte[64];
if (mInputStream == null) return;
size = mInputStream.read(buffer);
if (size > 0) {
onDataReceived(buffer, size);
}
} catch (IOException e) {
e.printStackTrace();
return;
}
}
}
}
protected void startSerialConnection(){
try {
mSerialPort = new SerialPort(new File("/dev/ttyS2"), 38400, 0);
} catch (SecurityException e) {
// TODO Auto-generated catch block
if(AppConfig.DEBUG)
Log.e("SERIAL", "portopen ERR: " + e.getMessage());
} catch (IOException e) {
// TODO Auto-generated catch block
if(AppConfig.DEBUG)
Log.e("SERIAL", "portopen ERR: " + e.getMessage());
}
mOutputStream = mSerialPort.getOutputStream();
mInputStream = mSerialPort.getInputStream();
/* Create a receiving thread */
mReadThread = new ReadThread();
mReadThread.start();
}
protected abstract void onDataReceived(final byte[] buffer, final int size);
protected abstract void writeSerial(byte[] buffer);
#Override
protected void onDestroy() {
if (mReadThread != null){
mReadThread.interrupt();
if(AppConfig.DEBUG) Log.i("ThreadSerial", "interrupting");
}
if(mSerialPort != null)
mSerialPort.close();
mSerialPort = null;
finish();
super.onDestroy();
}
}
I'm still in the process of learning Java and Android programming, so please forgive me if I'm doing something wrong. I looked up around, and the thing that you can't use variables other than "final" inside the RunOnUiThred came up. But I think it's not the issue, since it works the first time I start the activity.
Try doing your clean up in onPause() instead of onDestroy(), onDestroy() may not be called immediately which means there may be a read conflict on SerialPort. Also if you are already in onDestroy(), calling finish() doesn't really do anything.
Lastly, for a finite resource like SerialPort connection, it's better to put it in a Service.
I'm a newbie in Java, but I think I found out what was happening. The thing is that I asked the wrong question.
The problem is in the mInputStream.read(). As I've come to know, it's a blocking operation. I'm creating a thread that stays blocked in that read() method. After I finish the Activity, (go back to the first one), the thread keeps running. I know that because when a send some information through the serial interface, that thread responds.
So what I did, and it's working for me, altough many people stated that this method is not recommended is use mInputStream.available():
try {
if (mInputStream == null){ Log.i(tag,"returning"); return null ;}
Log.i(tag,"reading");
mEmptyStream = true;
while(mEmptyStream && !mFinish){
Log.i(tag,"input while");
/// checking if there is info, so we don't block the thread
if(mInputStream.available() > 0){
Log.i(tag,"input avail : " + InputStream.available());
//stream not empty
mEmptyStream = false;
size = mInputStream.read(buffer); //
}
}
if (size > 0) {
Log.i(tag,"size > 0 = " + new String(buffer, 0, size));
return new String(buffer,0,size);
}else{
Log.i(tag,"size <= 0");
}
}
Basically I loop using available(). When I finish the activity, in the onPause() method I set the field mFinish to true, this way the thread finds it's way out of execution and can end properly. It's the way I found and it's working so far. I improved the code significantly after the original post, like not running non UI jobs in the RunOnUiThread :)
But I tested it and it's working.

Categories

Resources