How to bring activity to front?

by mariush » Wed, 14 Apr 2010 14:55:47 GMT

Sponsored Links
Lets suppose that i have an activity A, that activity is moved to
background(function  moveTaskToBack is used), and after while i want
to bring this activity to front again. This code is used:
Activity A = getActivity();
Intent i = new Intent(A, A.getClass());

Activity is on screen, but when i invoke later moveTaskToBack on A
activity, activity is not moved to backgorund.
Does anyone know why?


How to bring activity to front?

by Liviu Ungureanu » Wed, 14 Apr 2010 17:03:53 GMT

 I think you cannot bring an activity to front after the activity called his
onPause() method without actions from user(start your application from menu,
from notification, resume it)  or without starting it from an service.

Maybe someone else know more but if you want to bring your activity to front
try to start it from an service if your application need one or notify the
user via notification and set the pending intent to start your activity.


Sponsored Links

How to bring activity to front?

by jpathak » Tue, 04 May 2010 02:43:29 GMT

 Its possible that you don't have the right context. If possible, try
storing the appropriate context in your own activity similar to a
singleton, and then calling startActivity on that context.


How to bring activity to front?

by jotobjects » Tue, 04 May 2010 03:55:32 GMT

 What are you trying to accomplish?  Do you expect to make the Activity
disappear and the prior one to appear as if you pressed the BACK key?
I think that is an incorrect understanding.

what parameter do you pass to moveTaskToBack and what is the return
value of the call?


Other Threads

1. scale whole view

I wrote a game using absolute positions for a specific device. I want
to target other resolutions however I want to minimize work. I just
want to scale the whole view down and maintain aspect ratio. I can see
in 3.0 there is a setScale function added that will do the job however
I want to target 1.5 onwards. I wrote this class that works ok
visually however the events are not working 100% i.e if you press dead
in the center of the button it will work if you touch a bit up it
presses the button on top even. Also it does draw the image button
pressed states correctly. However visually it is just what I want.

public class ScaledLinearLayout extends LinearLayout {

        private static final float OPTIMUM_HEIGHT = 1024;
        private static final float OPTIMUM_WIDTH = 768;
        private float offsetX;
        private float offsetY;
        private float scale = 1.0f;
        private Context context;
        private Display display;

        public ScaledLinearLayout(Context cxt, AttributeSet attrs) {
                super(cxt, attrs);
                this.context = cxt;

                WindowManager wm = (WindowManager)
                display = wm.getDefaultDisplay();
                float scaleX = display.getWidth() / OPTIMUM_WIDTH;
                float scaleY = display.getHeight() / OPTIMUM_HEIGHT;
                scale = Math.min( scaleX, scaleY );

                offsetX = (display.getWidth() - (scale * OPTIMUM_WIDTH)) / 2;
                offsetY = (display.getHeight() - (scale * OPTIMUM_HEIGHT)) / 2;

        public boolean dispatchTouchEvent(MotionEvent event) {

                float newX = (event.getX() - offsetX) / scale;
                float newY = (event.getY() - offsetY) / scale;
                event.setLocation(newX, newY);
                return super.dispatchTouchEvent(event);

        public void dispatchDraw(Canvas canvas) {

                canvas.scale(scale, scale);
                canvas.translate(offsetX, offsetY);

I make ScaledLinearLayout the parent viewgroup of my view and it will
then scale the views such that it best fits the screen and centers the
game on the screen. Only issue is the events are a bit whack. Any
ideas or a better way to do what I'm trying to achieve? Rewriting the
layouts are out of the question.


2. How to Install Android SDK on a MacBook (Pro)

I recently started developing android apps using a MacBook. The
documentation didn't capture the different issues I was having. Anyway
after a few hours of work, I got everything working ok.

So I documented the whole procedure here:

Hope this helps someone


3. Creating test application Dungeons

4. Dungeon Defenders: Second Wave Now Out For Xperia Play

5. setPreviewCallbackWithBuffer issue

6. bitmap prob

7. Start Activity from non-activity class