Is it possible to calll overridePendingTransition from "Service" (not Activity)

1,391 views
Skip to first unread message

QasewKim

unread,
Jul 8, 2010, 9:25:15 PM7/8/10
to android-porting
Hi,

I am beginner with Android(and java).
I am trying to make UI using Service. (which has view or viewgroup.)
And I need the Transition Effect when I start the Activity from this
Service.

1.
so I did something below.

=======================================
public class Myservice extends Service {

@Override
public IBinder onBind(Intent intent) {
return s;
}

private Myservice .Stub s = new Myservice .Stub(){
@Override

public void StartActivity() throws RemoteException {
Intent intent = new Intent(Intent.ACTION_VIEW);
intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
startActivity(intent);
overridePendingTransition (R.anim.left, R.anim.right) //
can't compile
}
=======================================
It failed.
only SomeActivity (that extends Activity) can call
overridePendingTransition(),
but Service can't.


2.
So I try this.
=======================================
...
private StartActivityImpl StartActivityImpl ;

public void StartActivity() throws RemoteException {
Intent intent = new Intent(Intent.ACTION_VIEW);
intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
startActivity(intent);
StartActivityImpl.StartactwithTransition();
}

};
private class StartActivityImpl extends Activity {

public void StartactwithTransition(){
overridePendingTransition(R.anim.left , R.anim.right ); //
complie ok
}
=======================================
It also failed.
I don't know why. (can you tell me why?)


3.
is it possible to add the code within Service.java like Activity.java
below?
=======================================
Activity.java
..
public void overridePendingTransition(int enterAnim, int exitAnim)
{
try {

ActivityManagerNative.getDefault().overridePendingTransition(
mToken, getPackageName(), enterAnim, exitAnim);
} catch (RemoteException e) {
}
}
=======================================
Service.java has mToken, too.
and it can call getPackageName();
so can I add this function to Service.java?


4.
or is it good way to use ActivityManagerNative, IActivityManager in
MyService?
( import ActivityManagerNative, IActivityManager
and call ActivityManagerNative.getDefault().overridePendingTransition(
and build internally using Android.mk)



5.
So my question is " How can i start activity with Transition Effect
from Service?"
If I have to modify the frameworks, I'll do that.

I don't care about modifying the frameworks,
so please give me your good tips (even though) in the view of a
platform developer.
I hope you help me!

Thanks!


Dianne Hackborn

unread,
Jul 9, 2010, 4:02:43 AM7/9/10
to conve...@gmail.com, android-porting
Sorry you can't do this.  UI flow is tied to activities, so you really need to make the call from there.  If you hack things up to be able to poke the window manager like that from elsewhere, you won't be doing it from the actual UI flow so in some cases will not be properly synchronized with it so have incorrect results.




--
Dianne Hackborn
Android framework engineer
hac...@android.com

Note: please don't send private questions to me, as I don't have time to provide private support, and so won't reply to such e-mails.  All such questions should be posted on public forums, where I and others can see and answer them.

QasewKim

unread,
Jul 9, 2010, 10:41:56 AM7/9/10
to android-porting
Dear Dianne Hackborn,

I am very glad to see your help.
I've always read your posts.

so it seems that I have to find some other ways.

Thank you very much.
> > unsubscribe: android-porti...@googlegroups.com<android-porting%2Bunsubscribe@ googlegroups.com>
> > website:http://groups.google.com/group/android-porting
>
> --
> Dianne Hackborn
> Android framework engineer
> hack...@android.com
Reply all
Reply to author
Forward
0 new messages