  	
  	if((screen = SDL_SetVideoMode(w, h, suggestedBpp, SDL_SWSURFACE|(fullscreen?SDL_FULLSCREEN:0))) == NULL)
  	{
-@@ -717,3 +744,4 @@
+@@ -583,14 +607,27 @@
+ 	setResolution = true;
+ }
+ 
++
+ static void listenForEvents()
+ {
+-	while(1) //main SDL events loop
+-	{
++	while(loopListenForEvents(true)); //main SDL events loop
++}
++
++static bool loopListenForEvents(bool block)
++{
+ 		SDL_Event *ev = new SDL_Event();
+ 
+ 		//tlog0 << "Waiting... ";
+-		int ret = SDL_WaitEvent(ev);
++		int ret = 1;
++		if( block )
++			ret = SDL_WaitEvent(ev);
++		else
++		{
++			if(!SDL_PollEvent(ev)) {
++				delete ev;
++				return false;
++			}
++		}
+ 		//tlog0 << "got " << (int)ev->type;
+ 		if (ret == 0 || (ev->type==SDL_QUIT) ||
+ 			(ev->type == SDL_KEYDOWN && ev->key.keysym.sym==SDLK_F4 && (ev->key.keysym.mod & KMOD_ALT)))
+@@ -609,7 +646,7 @@
+ 			SDL_Delay(750);
+ 			SDL_Quit();
+ 			tlog0 << "Ending...\n";
+-			break;
++			return false;
+ 		}
+ 		else if(LOCPLINT && ev->type == SDL_KEYDOWN && ev->key.keysym.sym==SDLK_F4)
+ 		{
+@@ -618,7 +655,7 @@
+ 			setScreenRes(conf.cc.screenx, conf.cc.screeny, conf.cc.bpp, full);
+ 			GH.totalRedraw();
+ 			delete ev;
+-			continue;
++			return true;
+ 		}
+ 		else if(ev->type == SDL_USEREVENT)
+ 		{
+@@ -648,7 +685,7 @@
+ 			}
+ 
+ 			delete ev;
+-			continue;
++			return true;
+ 		} 
+ 
+ 		//tlog0 << " pushing ";
+@@ -656,7 +693,7 @@
+ 		events.push(ev);
+ 		eventsM.unlock();
+ 		//tlog0 << " done\n";
+-	}
++		return true;
+ }
+ 
+ void startGame(StartInfo * options, CConnection *serv/* = NULL*/) 
+@@ -717,3 +754,4 @@
  	ev.user.code = 1;
  	SDL_PushEvent(&ev);
  }
 +
-Index: client/CVideoHandler.cpp
-===================================================================
---- client/CVideoHandler.cpp	(revision 2170)
-+++ client/CVideoHandler.cpp	(working copy)
-@@ -6,6 +6,7 @@
- #include "SDL_Extensions.h"
- #include "CPlayerInterface.h"
- #include "boost/filesystem.hpp"
-+
- 
- extern SystemOptions GDefaultOptions; 
- //reads events and returns true on key down
-@@ -62,6 +63,7 @@
- void DLLHandler::Instantiate(const char *filename)
- {
- 	name = filename;
-+	tlog1 << "Loading dynamic library " << filename << std::endl;
- #ifdef _WIN32
- 	dll = LoadLibraryA(filename);
- 	if(!dll)
-@@ -72,6 +74,7 @@
- #else
- 	dll = dlopen(filename,RTLD_LOCAL | RTLD_LAZY);
- #endif
-+	tlog1 << "Loading dynamic library " << filename << dll ? " successful" : " failed" <<std::endl;
- }
- 
- void *DLLHandler::FindAddress(const char *symbol)
-@@ -86,6 +89,10 @@
- 	}
- #else
- 	ret = (void *)dlsym(dll, symbol);
-+	if(!ret)
-+	{
-+		tlog1 << "Failed to find " << symbol << " in " << name << std::endl;
-+	}
- #endif
- 	return ret;
- }
+Index: client/GUIBase.h
+===================================================================
+--- client/GUIBase.h	(revision 2170)
++++ client/GUIBase.h	(working copy)
+@@ -546,6 +546,8 @@
+ 	CGuiHandler();
+ 	~CGuiHandler();
+ 	void run(); // holds the main loop for the whole program after initialization and manages the update/rendering system
++	void loopInitFromMainThread();
++	bool loopFromMainThread();
+ 	
+ 	void totalRedraw(); //forces total redraw (using showAll), sets a flag, method gets called at the end of the rendering
+ 	void simpleRedraw(); //update only top interface and draw background from buffer, sets a flag, method gets called at the end of the rendering

 };
 
 extern DLL_EXPORT CLogger tlog0; //green - standard progress info
Index: client/CMT.cpp
===================================================================
--- client/CMT.cpp	(revision 2170)
+++ client/CMT.cpp	(working copy)
@@ -55,6 +55,8 @@
 #if __MINGW32__
 #undef main
 #endif
+
+
 
 namespace po = boost::program_options;
 
@@ -92,6 +94,7 @@
 static void listenForEvents();
 void requestChangingResolution();
 void startGame(StartInfo * options, CConnection *serv = NULL);
+
 
 #ifndef _WIN32
 #ifndef _GNU_SOURCE
@@ -102,6 +105,7 @@
 
 void init()
 {
+	__android_log_print(ANDROID_LOG_DEBUG, "VCMI", "Check at %s in %s:%i", __FUNCTION__, __FILE__, __LINE__);
 	timeHandler tmh, pomtime;
 #if SDL_BYTEORDER == SDL_BIG_ENDIAN
 	int rmask = 0xff000000;int gmask = 0x00ff0000;int bmask = 0x0000ff00;int amask = 0x000000ff;
@@ -157,8 +161,11 @@
 	tlog0<<"\tMain graphics: "<<tmh.getDif()<<std::endl;
 	tlog0<<"Initializing game graphics: "<<tmh.getDif()<<std::endl;
 
+	__android_log_print(ANDROID_LOG_DEBUG, "VCMI", "Check at %s in %s:%i", __FUNCTION__, __FILE__, __LINE__);
 	CMessage::init();
+	__android_log_print(ANDROID_LOG_DEBUG, "VCMI", "Check at %s in %s:%i", __FUNCTION__, __FILE__, __LINE__);
 	tlog0<<"Message handler: "<<tmh.getDif()<<std::endl;
+	__android_log_print(ANDROID_LOG_DEBUG, "VCMI", "Check at %s in %s:%i", __FUNCTION__, __FILE__, __LINE__);
 	//CPG = new CPreGame(); //main menu and submenus
 	//tlog0<<"Initialization CPreGame (together): "<<tmh.getDif()<<std::endl;
 }
@@ -184,19 +191,26 @@
 }
 
 

 #endif
+#endif
 {
 	tlog0 << "Starting... " << std::endl;      
 	po::options_description opts("Allowed options");
@@ -235,7 +246,6 @@
 	console->start();
 	atexit(dispose);
 	tlog0 <<"Creating console and logfile: "<<pomtime.getDif() << std::endl;
-
 	conf.init();
 	tlog0 <<"Loading settings: "<<pomtime.getDif() << std::endl;
 	tlog0 << NAME << std::endl;
@@ -260,14 +270,18 @@
 	tlog0<<"\tInitializing video: "<<pomtime.getDif()<<std::endl;
 
 	//we can properly play intro only in the main thread, so we have to move loading to the separate thread
-	boost::thread loading(init);
-
+#ifdef ANDROID
+	init();
 	if(!vm.count("battle") && !vm.count("nointro"))
 		playIntro();
+#else
+	boost::thread loading(init);
 
+
 	SDL_FillRect(screen,NULL,0);
 	CSDL_Ext::update(screen);
 	loading.join();
+#endif
 	tlog0<<"Initialization of VCMI (together): "<<total.getDif()<<std::endl;
 
 	if(!vm.count("battle"))
@@ -284,8 +298,16 @@
 		si->playerInfos[1].color = 1;
 		startGame(si);
 	}
+#ifdef ANDROID
+	GH.loopInitFromMainThread();
+	while( GH.loopFromMainThread() )
+	{
+		while( loopListenForEvents(false) );
+	}
+#else
 	mainGUIThread = new boost::thread(&CGuiHandler::run, boost::ref(GH));
 	listenForEvents();
+#endif
 
 	return 0;
 }
@@ -535,10 +557,12 @@
 		tlog2 << "Warning: SDL says that "  << bpp << "bpp is wrong and suggests " << suggestedBpp << std::endl;
 	}
 
