Leaving an activity from a thread

All your problems with Audio, Video and Images.

Leaving an activity from a thread

Postby frank » Thu Jun 18, 2009 11:28 pm

I am wondering :oops: what might be the best method for going back to the MainMenu Activity from a graphical thread.

A brief summary of my configuration :

- MainMenu Activity launches a SubActivity that in turns creates a SurfaceView with a thread (for the graphic rendering).

When the game is over, I display some information from the thread and would like go back to the MainMenu Activity when the screen is touched (like when the user presses the BACK key).

- Actually, I forward touch events from the SurfaceView to the Thread. Returning to the MainMenu Activity from SurfaceView should be quiet good too but I have no idea on how to do it.

Actually I can't figure out how to do it without putting in place some message handler (seems quiet tricky).

Any ideas :shock: ?

Thanks
frank
frank
Freshman
Freshman
 
Posts: 4
Joined: Thu Jun 18, 2009 11:12 pm

Top

Postby WarrenFaith » Fri Jun 19, 2009 6:59 am

Build up a Intent-circle :)
Menu -> Intent1
SurfaceView -> Intent2

You just have to call a new intent if you want to go back to menu. But dont forget to destroy the SurfaceView-Activity including the Thread(s).
WarrenFaith
Moderator
Moderator
 
Posts: 227
Joined: Fri Mar 13, 2009 10:59 am
Location: Berlin, Germany

Postby frank » Fri Jun 19, 2009 5:07 pm

Thanks I finally found how to start the Activity MainMenu from the Surface View.

Syntax: [ Download ] [ Hide ]
Using java Syntax Highlighting
  1.  
  2.    // this from within a OnTouchListener -- methode : onTouch(View v, MotionEvent event)                        
  3.  
  4.    Intent i = new Intent(v.getContext(), MainMenu.class);
  5.  
  6.    v.getContext().startActivity(i);
  7.  
  8.  
Parsed in 0.035 seconds, using GeSHi 1.0.8.4


The problem now is that the Activity that created the SurfaceView doesn't receive any finish events.
The problem is that when I select the option, this View will be recreated ... leaks !!! :cry:

I searched a while but couldn't find anyway to notify it from the SurfaceView in order to finish() it !?

Next try is to create a system of notification (like in LunarLander perhaps)... I will keep you informed.
Nevertheless, I am wondering if no other simple solution exists !

:roll:
frank
Freshman
Freshman
 
Posts: 4
Joined: Thu Jun 18, 2009 11:12 pm

Postby frank » Mon Jun 22, 2009 11:17 pm

Ok, I had a look at my problem without succes... :roll:

Actually my question is simple but certainly not well formulated :

--> How to "quit" an Activity when the screen is touched - I mean from a Thread(that draws onto a SurfaceView) or from a SurfaceView ?


By "quit" I mean "simulate" the "BACK" key - which implies that the Activity will be destroyed and the previous one Restored (if any ).

Is there a simple way to do that ? :cry: At first look it seems pretty straight forward :P

Many Thanks
frank
Freshman
Freshman
 
Posts: 4
Joined: Thu Jun 18, 2009 11:12 pm

Postby Sowmya » Tue Jun 23, 2009 12:20 pm

You can call finish from SurfaceView like this

Syntax: [ Download ] [ Hide ]
Using java Syntax Highlighting
  1. ((Activity) context).finish();
Parsed in 0.033 seconds, using GeSHi 1.0.8.4


Hope this helps
Sowmya
Experienced Developer
Experienced Developer
 
Posts: 51
Joined: Fri Mar 06, 2009 7:49 am

Postby frank » Wed Jun 24, 2009 5:21 pm

Many thanks Sowmya.

That's exactly what I was looking for & it is working fine 8)

Nice to learn that the context is the Activity in a SurfaceView !!!

See you
frank
Freshman
Freshman
 
Posts: 4
Joined: Thu Jun 18, 2009 11:12 pm

Top

Return to Multimedia Problems

Who is online

Users browsing this forum: Exabot [Bot], Yahoo [Bot] and 20 guests