Hi there, What I want: I have a project that consist of 2 Activities, the first one extends IOIOActivity and is showing the main screen and responsible for detecting and creating IOIO connection (through a Looper extending BaseIOIOLooper). When IOIO connection is established, a button will be enabled. Clicking this button will start a second Activity which extends FragmentActivity.
The second Activity will be handling the control of the IOIO peripheral (DIgitalIO, I2C, etc). When a disconnection is detected, the second Activity should be destroyed and the first Activity should be shown. What actually happens: When the second Activity is started, it seems that the IOIO object as created by the Looper class will be disconnected and the disconnected() method is called. Can anyone please help? Attached is the code and layout for the first Activity and the AndroidManifest. -- You received this message because you are subscribed to the Google Groups "ioio-users" group. To unsubscribe from this group and stop receiving emails from it, send an email to [email protected]. To post to this group, send email to [email protected]. Visit this group at http://groups.google.com/group/ioio-users. For more options, visit https://groups.google.com/groups/opt_out.
/**
*
*/
package com.example.dummyioio;
import ioio.lib.api.IOIO;
import ioio.lib.api.exception.ConnectionLostException;
import ioio.lib.util.BaseIOIOLooper;
import ioio.lib.util.IOIOLooper;
import ioio.lib.util.android.IOIOActivity;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
/**
* @author lcc
*
*/
public class MainActivity extends IOIOActivity {
public static IOIO ioio;
private Button button;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
button = (Button) findViewById(R.id.button);
button.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
Intent intent = new Intent(getApplicationContext(), ItemListActivity.class);
startActivity(intent);
}
});
enableUi(false);
}
private class Looper extends BaseIOIOLooper {
@Override
public void setup() throws ConnectionLostException {
ioio = ioio_;
enableUi(true);
}
@Override
public void loop() throws ConnectionLostException, InterruptedException {
Thread.sleep(10000);
}
@Override
public void disconnected() {
enableUi(false);
// TODO: can do this?
Intent intent = new Intent(getApplicationContext(), MainActivity.class);
intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
startActivity(intent);
}
}
@Override
protected IOIOLooper createIOIOLooper() {
return new Looper();
}
private void enableUi(final boolean enable) {
runOnUiThread(new Runnable() {
@Override
public void run() {
button.setEnabled(enable);
}
});
}
}
AndroidManifest.xml
Description: XML document
activity_main.xml
Description: XML document
