In order that my connection to ioio will not die upon the phone screen shutting down, I put most of the ioio activity into a separate class.
I have a text view and a button defined on the main activity.
I defined a constructor in IoioTerbiumActivity which takes as an input the MainActivity object. That way I can control the text view and button from inside IoioTerbiumActivity.
When I tried the project, it showed the text view and the button but clearly did not start my ioio class.
It clearly doesn't make sense to create the class and then call startActivity with a new intent. If I just call startActivity, how do I bring across the parent class?
If I use the my1 from the constructor, what is the proper way to start the activity?
public class MainActivity extends AppCompatActivity {
TextView timerView;
int runState = 0;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
timerView = (TextView) findViewById(R.id.timerView);
Button b = (Button) findViewById(R.id.startBut);
b.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
String txtTmp = getString(R.string.start_lab);
Button b = (Button) v;
switch (runState) {
case 0:
case 1:
txtTmp = getString(R.string.stop_lab);
runState++;
break;
case 2:
runState++;
break;
default:
runState = 0;
break;
}
b.setText(txtTmp);
}
});
// IoioTerbiumActivity my1 = new IoioTerbiumActivity(this);
// startActivity(new Intent(this,IoioTerbiumActivity.class));
}
}
--
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 ioio-users+...@googlegroups.com.
To post to this group, send email to ioio-...@googlegroups.com.
Visit this group at https://groups.google.com/group/ioio-users.
For more options, visit https://groups.google.com/d/optout.
Hi Ytai,
I almost gave up on getting a reply from you, since my problem isn't connected to the IOIO board as such but is an android problem.
I have written tons of code in regular Java but android is a different mind set. In regular Java I make a constructor to a dialog or whatever else I want to use and then I call functions in the instantiated class. Here things just come alive by themselves.
The problem with everything in a single file was that when the android screen turned off, it would disconnect the IOIO board, but my timer would keep counting. You can see my initial bias was to use a constructor and then somehow start the IOIO - and stop the IOIO when I am finished. I had no idea what exactly to call in "my1", assuming there is something in the IOIOActivity which will start the board. The only thing I could find was startActivity but that used new intent.
It is totally unclear to me why having the code in a separate file would make any real difference. If I understand you correctly you are saying have the loop going always, but perhaps have the code which it operates in a separate object. Then I would never "start" or "stop" the IOIO itself but only control what it is doing in a separate object. I can't see how that would make any difference, since it is the card itself which is losing connection. I thought that if I could somehow start and stop the card itself, then it would no longer loose connection when the android screen goes off. It isn't clear to me who is telling the IOIO to drop the connection, and why.
Once I see what the answer is, it will probably look very simple but at the moment it is all black magic. Somehow I need to get control and not have the card drop the connection whenever the screen goes blank or some other event. I looked at the source code for IOIOActivity and it didn't give me much. That code is the interface and I need something which calls it - something that does start and stop on the board itself. At least this is what I think I need.
Thanks,
Ilan
Why don't you use ioioservice and communicate to the activities throughout intents or use something like eventbus