Rams
2011-03-14 17:41:49 UTC
OK, so I have a Service which I want to be able to start (3rd party)
Activities and stop them as necessary. A simple example would be
detecting that headphones are plugged in and starting the Music app,
then stopping it when they are unplugged,
I've explored a number of ways to do this, but the only way seems to
be for the Service to start an Activity which then starts a sub-
activity. This much, I've accomplished and is pretty straight-forward.
My issue comes with shutting down the child Activity. I know it can be
done, since I have knocked up a Proof Of Concept project to check this
functionality. My POC has an Activity with a 'Go' button with the
following code:
Button button = (Button) findViewById(R.id.button);
button.setOnClickListener(new OnClickListener() {
@Override public void onClick(View v) {
Intent intent = new Intent();
intent.setComponent(new
ComponentName("com.android.spare_parts",
"com.android.spare_parts.SpareParts"));
startActivityForResult(intent, 17);
try {
Thread.sleep(3500);
}
catch (InterruptedException e) {
e.printStackTrace();
}
finishActivity(17);
}
});
This works exaclty as expected.
My issue is that when I incorporate this principle into my app, the
call to finishActivity() does nothing.
Services can't start another Activity for result, so it starts an
intermediary Activity. The intermediary Activity then starts the 3rd
Party Activity. All this works fine.
The issue is that when the intermediary calls finishActivity(), the
3rd Party Activity continues running. I don't understand this, since
my POC project does not suffer from this problem.
There is a suspicious warning message in the Android console stating,
"Activity is launching as a new task, so cancelling activity result.",
but I suspect that this might be erroneous...
The obvious difference between the POC project and my app is that my
app is a Service which starts an intermediary Activity to control the
3rd party Activity. Is it possible that the intermediary Activity is a
'child' of the Service and is therefore unable to finish sub-
Activities?
+---------+ +-----------------------+ +--------------------+
| Service | -> | Intermediary Activity | -> | 3rd Party Activity |
+---------+ +-----------------------+ +--------------------+
Activities and stop them as necessary. A simple example would be
detecting that headphones are plugged in and starting the Music app,
then stopping it when they are unplugged,
I've explored a number of ways to do this, but the only way seems to
be for the Service to start an Activity which then starts a sub-
activity. This much, I've accomplished and is pretty straight-forward.
My issue comes with shutting down the child Activity. I know it can be
done, since I have knocked up a Proof Of Concept project to check this
functionality. My POC has an Activity with a 'Go' button with the
following code:
Button button = (Button) findViewById(R.id.button);
button.setOnClickListener(new OnClickListener() {
@Override public void onClick(View v) {
Intent intent = new Intent();
intent.setComponent(new
ComponentName("com.android.spare_parts",
"com.android.spare_parts.SpareParts"));
startActivityForResult(intent, 17);
try {
Thread.sleep(3500);
}
catch (InterruptedException e) {
e.printStackTrace();
}
finishActivity(17);
}
});
This works exaclty as expected.
My issue is that when I incorporate this principle into my app, the
call to finishActivity() does nothing.
Services can't start another Activity for result, so it starts an
intermediary Activity. The intermediary Activity then starts the 3rd
Party Activity. All this works fine.
The issue is that when the intermediary calls finishActivity(), the
3rd Party Activity continues running. I don't understand this, since
my POC project does not suffer from this problem.
There is a suspicious warning message in the Android console stating,
"Activity is launching as a new task, so cancelling activity result.",
but I suspect that this might be erroneous...
The obvious difference between the POC project and my app is that my
app is a Service which starts an intermediary Activity to control the
3rd party Activity. Is it possible that the intermediary Activity is a
'child' of the Service and is therefore unable to finish sub-
Activities?
+---------+ +-----------------------+ +--------------------+
| Service | -> | Intermediary Activity | -> | 3rd Party Activity |
+---------+ +-----------------------+ +--------------------+
--
You received this message because you are subscribed to the Google
Groups "Android Developers" group.
To post to this group, send email to android-***@googlegroups.com
To unsubscribe from this group, send email to
android-developers+***@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en
You received this message because you are subscribed to the Google
Groups "Android Developers" group.
To post to this group, send email to android-***@googlegroups.com
To unsubscribe from this group, send email to
android-developers+***@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en