Reputation: 3143
I have RoomActivity and GameActivity. RoomActivity listen server commands. Server can send 2 commands: openGameActivity and closeGameActivity. This commands must to run only in RoomActivity. First command I do so (RoomActivity class):
if(request == "open")
{
Intent i = new Intent(this, GameActivity.class);
startActivity(i);
}
But I have problem with second command.
if(request == "close")
{
//What I must do here to return back to RoomActivity?
}
Structure:
Upd About finish(); I cant's use it because it's static method: RoomActivity:
GameActivity.finishAct();
GameActivity:
public static void finishAct()
{
//this.onBackPressed();
finish();//<====Cannot make a static reference to the non-static method finish() from the type Activity
}
Upvotes: 0
Views: 428
Reputation: 2558
Not sure how you are implementing these "Commands" as you haven't provided any code, but if you're not already I'd suggest using BroadcastIntent's from your service. Register the GameActivity to listen for the close broadcast and the RoomActivity for the open game broadcast.
You register BroadcastReceiver's in the onResume() method of an activity and unregister it onPause().
http://developer.android.com/reference/android/content/BroadcastReceiver.html
As other's have said, once the GameActivity receives the close broadcast it could simply call finish() on itself.
Upvotes: 0
Reputation: 20885
You'll likely review your code to set finishAct to nonstatic. It doesn't make sense to declare and use a method like that. It's also not like Activities are intended to be implemented
Upvotes: 0