Fixed app crashing during data download
This commit is contained in:
@@ -95,6 +95,13 @@ class DataDownloader extends Thread
|
||||
Status = _Status;
|
||||
Parent = _Parent;
|
||||
}
|
||||
public void setParent( TextView _Status, MainActivity _Parent )
|
||||
{
|
||||
synchronized(DataDownloader.this) {
|
||||
Status = _Status;
|
||||
Parent = _Parent;
|
||||
}
|
||||
}
|
||||
|
||||
public void setText(final String str)
|
||||
{
|
||||
@@ -107,10 +114,13 @@ class DataDownloader extends Thread
|
||||
Status.setText(text + "\n" + Globals.ReadmeText);
|
||||
}
|
||||
}
|
||||
Callback cb = new Callback();
|
||||
cb.text = new String(str);
|
||||
cb.Status = Status;
|
||||
Parent.runOnUiThread(cb);
|
||||
synchronized(DataDownloader.this) {
|
||||
Callback cb = new Callback();
|
||||
cb.text = new String(str);
|
||||
cb.Status = Status;
|
||||
if( Parent != null && Status != null )
|
||||
Parent.runOnUiThread(cb);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
@@ -120,8 +130,19 @@ class DataDownloader extends Thread
|
||||
DownloadComplete = false;
|
||||
Status = new StatusWriter( _Status, _Parent );
|
||||
Status.setText( "Connecting to " + Globals.DataDownloadUrl );
|
||||
outFilesDir = Parent.getFilesDir().getAbsolutePath();
|
||||
if( Globals.DownloadToSdcard )
|
||||
outFilesDir = "/sdcard/" + Globals.ApplicationName;
|
||||
this.start();
|
||||
}
|
||||
|
||||
public void setParent(MainActivity _Parent, TextView _Status)
|
||||
{
|
||||
synchronized(this) {
|
||||
Parent = _Parent;
|
||||
Status.setParent( _Status, _Parent );
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void run()
|
||||
@@ -296,23 +317,25 @@ class DataDownloader extends Thread
|
||||
public MainActivity Parent;
|
||||
public void run()
|
||||
{
|
||||
Parent.initSDL();
|
||||
Parent.initSDL();
|
||||
}
|
||||
}
|
||||
Callback cb = new Callback();
|
||||
cb.Parent = Parent;
|
||||
Parent.runOnUiThread(cb);
|
||||
synchronized(this) {
|
||||
cb.Parent = Parent;
|
||||
if(Parent != null)
|
||||
Parent.runOnUiThread(cb);
|
||||
}
|
||||
}
|
||||
|
||||
private String getOutFilePath(final String filename)
|
||||
{
|
||||
if( Globals.DownloadToSdcard )
|
||||
return "/sdcard/" + Globals.ApplicationName + "/" + filename;
|
||||
return Parent.getFilesDir().getAbsolutePath() + "/" + filename;
|
||||
return outFilesDir + "/" + filename;
|
||||
};
|
||||
|
||||
public boolean DownloadComplete;
|
||||
public StatusWriter Status;
|
||||
private MainActivity Parent;
|
||||
private String outFilesDir = null;
|
||||
}
|
||||
|
||||
|
||||
@@ -22,16 +22,20 @@ public class MainActivity extends Activity {
|
||||
getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,
|
||||
WindowManager.LayoutParams.FLAG_FULLSCREEN);
|
||||
|
||||
TextView tv = new TextView(this);
|
||||
tv.setText("Initializing");
|
||||
setContentView(tv);
|
||||
downloader = new DataDownloader(this, tv);
|
||||
_tv = new TextView(this);
|
||||
_tv.setText("Initializing");
|
||||
setContentView(_tv);
|
||||
if( downloader == null )
|
||||
downloader = new DataDownloader(this, _tv);
|
||||
mLoadLibraryStub = new LoadLibrary();
|
||||
mAudioThread = new AudioThread(this);
|
||||
}
|
||||
|
||||
public void initSDL()
|
||||
{
|
||||
mLoadLibraryStub = new LoadLibrary();
|
||||
mAudioThread = new AudioThread(this);
|
||||
if(sdlInited)
|
||||
return;
|
||||
sdlInited = true;
|
||||
mGLView = new DemoGLSurfaceView(this);
|
||||
setContentView(mGLView);
|
||||
// Receive keyboard events
|
||||
@@ -45,6 +49,9 @@ public class MainActivity extends Activity {
|
||||
|
||||
@Override
|
||||
protected void onPause() {
|
||||
synchronized( downloader ) {
|
||||
downloader.setParent(null, null);
|
||||
}
|
||||
// TODO: if application pauses it's screen is messed up
|
||||
if( wakeLock != null )
|
||||
wakeLock.release();
|
||||
@@ -60,11 +67,19 @@ public class MainActivity extends Activity {
|
||||
super.onResume();
|
||||
if( mGLView != null )
|
||||
mGLView.onResume();
|
||||
synchronized( downloader ) {
|
||||
downloader.setParent(this, _tv);
|
||||
if( downloader.DownloadComplete )
|
||||
initSDL();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onStop()
|
||||
{
|
||||
synchronized( downloader ) {
|
||||
downloader.setParent(null, null);
|
||||
}
|
||||
if( wakeLock != null )
|
||||
wakeLock.release();
|
||||
|
||||
@@ -102,6 +117,8 @@ public class MainActivity extends Activity {
|
||||
private LoadLibrary mLoadLibraryStub = null;
|
||||
private AudioThread mAudioThread = null;
|
||||
private PowerManager.WakeLock wakeLock = null;
|
||||
private DataDownloader downloader = null;
|
||||
private static DataDownloader downloader = null;
|
||||
private TextView _tv = null;
|
||||
private boolean sdlInited = false;
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user