How to go to the previous Activity?

  ... discussions about development with the GLES2 branch of AndEngine.

How to go to the previous Activity?

Postby Brujojorge » Tue Oct 15, 2013 1:46 pm

Hello guys,
im trying to go the previous Activity when I'm in a subclass AnimatedSprite of BaseGameActivity.
I can do it easily when you are in a class that extends Activity with
Intent intent = new Intent(CurrentActivity.this, ActivityYouWantToGo.class);
startActivity(intent);

any ideas??
Brujojorge
 
Posts: 10
Joined: Tue Oct 30, 2012 6:40 pm

Re: How to go to the previous Activity?

Postby smartus » Tue Oct 15, 2013 5:21 pm

This is not an AndEngine question or Android question. It's a Java or OO question - what you need is to get a reference to the Context (or your first activity, because it extends Context).

For simplicity, have one manager class that will have a reference to the context. Either static reference or make it a singleton with a static getInstance() method and the a regular field.

Syntax: [ Download ] [ Hide ]
Using java Syntax Highlighting
  1. public class MyManager {
  2.  
  3. public static Context CTX;
  4.  
  5. }
Parsed in 0.012 seconds, using GeSHi 1.0.8.4


.. then in createEngineOptions call:

Syntax: [ Download ] [ Hide ]
Using java Syntax Highlighting
  1. MyManager.CTX = this; //this is the current activity starting the engine, remember, it is a context as well
Parsed in 0.010 seconds, using GeSHi 1.0.8.4



Afterwards you can use it:

Syntax: [ Download ] [ Hide ]
Using java Syntax Highlighting
  1. Intent i = new Intent(MyManager.CTX, ...);
Parsed in 0.010 seconds, using GeSHi 1.0.8.4


This is the ugliest solution, but the easiest to type :)
User avatar
smartus
 
Posts: 510
Joined: Fri May 10, 2013 4:17 pm

Re: How to go to the previous Activity?

Postby Brujojorge » Tue Oct 15, 2013 7:53 pm

YEs, I know it.
Sorry, i didn't explain that my probles is exactly with the startActivity(intent);
I can´t call it after declare the Intent because i have the error:
Cannot make a static reference to the non-static method startActivity(Intent) from the type Activity

Thanks anyway :D
Brujojorge
 
Posts: 10
Joined: Tue Oct 30, 2012 6:40 pm

Re: How to go to the previous Activity?

Postby smartus » Tue Oct 15, 2013 8:21 pm

Brujojorge wrote:YEs, I know it.
Sorry, i didn't explain that my probles is exactly with the startActivity(intent);
I can´t call it after declare the Intent because i have the error:
Cannot make a static reference to the non-static method startActivity(Intent) from the type Activity

Thanks anyway :D


Because you are not using the reference to the instance. Are you trying to call this from static method? What I wrote still stands.
User avatar
smartus
 
Posts: 510
Joined: Fri May 10, 2013 4:17 pm

Re: How to go to the previous Activity?

Postby Brujojorge » Tue Oct 15, 2013 8:38 pm

Yes, I need to call the StartActivity(intent); from a static method, and that error is showed :?
I tried to build a non function to call from the static method that I need but i can´t do it neither :x
If i call it from a non static method it works well.
Last edited by Brujojorge on Tue Oct 15, 2013 8:41 pm, edited 1 time in total.
Brujojorge
 
Posts: 10
Joined: Tue Oct 30, 2012 6:40 pm

Re: How to go to the previous Activity?

Postby smartus » Tue Oct 15, 2013 8:40 pm

Brujojorge wrote:Yes, I need to call the StartActivity(intent); from a static method, and that error is showed :x
If i call it from a non static method it works well.


It's a compile error. Post your full code. You simply have to use the instance and call the method on that instance.
User avatar
smartus
 
Posts: 510
Joined: Fri May 10, 2013 4:17 pm

Re: How to go to the previous Activity?

Postby alexadam1212 » Tue Dec 24, 2013 3:53 am

sorry ,im a new noob maybe some onel else can help you ! :D
alexadam1212
 
Posts: 1
Joined: Mon Dec 23, 2013 6:39 pm


Return to GLES2

Who is online

Users browsing this forum: Google Adsense [Bot] and 133 guests