public boolean request(Object soaprequest) { if (!checkSoapMemberVariable()) return false; ServiceRequest req = new ServiceRequest( this.ServerUrl, this.SoapAction, this.NameSpace, this.MethodName, this.SoapVersion, this.DotNet, (SoapObject) soaprequest); Thread thread = new Thread(req); try { thread.start(); thread.join(); } catch (Exception e) { this.Response = null; e.printStackTrace(); return false; } this.Response = req.getResponse(); if (this.Response == null) return false; return true; }
public void start() { if (myThread == null) { Log.i(getClass().getName(), "Main thread.start()"); myThread = new Thread(this); myThread.start(); } else { Log.w( getClass().getName(), "Requested a thread.start(), but the thread is already running - ignoring this request! (myThread = " + myThread); } }
@Override public void onCreate(Bundle savedInstanceState) { Log.d(TAG, "onCreate"); super.onCreate(savedInstanceState); Thread.currentThread().setUncaughtExceptionHandler(this); setContentView(R.layout.main); inputView = (EditText) findViewById(R.id.input_view); inputView.setOnEditorActionListener(this); listAdapter = new ArrayAdapter<String>(this, R.layout.row); listAdapter.setNotifyOnChange(true); resultsView = (ListView) this.findViewById(R.id.results_view); resultsView.setAdapter(listAdapter); resultsView.setOnItemClickListener(this); }
/** Called when the activity is first created. */ @Override public void onCreate(Bundle savedInstanceState) { mAppContext = this; mMainHandler = new Handler(); if (!sTryCatchAttached) { sTryCatchAttached = true; mMainHandler.post( new Runnable() { public void run() { try { Looper.loop(); } catch (Exception e) { Log.e(LOG_FILE_NAME, "top level exception", e); StringWriter sw = new StringWriter(); PrintWriter pw = new PrintWriter(sw); e.printStackTrace(pw); pw.flush(); GeckoAppShell.reportJavaCrash(sw.toString()); } // resetting this is kinda pointless, but oh well sTryCatchAttached = false; } }); } SharedPreferences settings = getPreferences(Activity.MODE_PRIVATE); String localeCode = settings.getString(getPackageName() + ".locale", ""); if (localeCode != null && localeCode.length() > 0) GeckoAppShell.setSelectedLocale(localeCode); Log.i(LOG_FILE_NAME, "create"); super.onCreate(savedInstanceState); if (sGREDir == null) sGREDir = new File(this.getApplicationInfo().dataDir); getWindow() .setFlags( mFullscreen ? WindowManager.LayoutParams.FLAG_FULLSCREEN : 0, WindowManager.LayoutParams.FLAG_FULLSCREEN); if (cameraView == null) { cameraView = new SurfaceView(this); cameraView.getHolder().setType(SurfaceHolder.SURFACE_TYPE_PUSH_BUFFERS); } if (surfaceView == null) surfaceView = new GeckoSurfaceView(this); else mainLayout.removeAllViews(); mainLayout = new AbsoluteLayout(this); mainLayout.addView( surfaceView, new AbsoluteLayout.LayoutParams( AbsoluteLayout.LayoutParams.MATCH_PARENT, // level 8 AbsoluteLayout.LayoutParams.MATCH_PARENT, 0, 0)); setContentView( mainLayout, new ViewGroup.LayoutParams( ViewGroup.LayoutParams.FILL_PARENT, ViewGroup.LayoutParams.FILL_PARENT)); mConnectivityFilter = new IntentFilter(); mConnectivityFilter.addAction(ConnectivityManager.CONNECTIVITY_ACTION); mConnectivityReceiver = new GeckoConnectivityReceiver(); IntentFilter batteryFilter = new IntentFilter(); batteryFilter.addAction(Intent.ACTION_BATTERY_CHANGED); mBatteryReceiver = new GeckoBatteryManager(); registerReceiver(mBatteryReceiver, batteryFilter); if (SmsManager.getInstance() != null) { SmsManager.getInstance().start(); } GeckoNetworkManager.getInstance().init(); if (!checkAndSetLaunchState(LaunchState.PreLaunch, LaunchState.Launching)) return; checkAndLaunchUpdate(); mLibLoadThread = new Thread( new Runnable() { public void run() { // At some point while loading the gecko libs our default locale gets set // so just save it to locale here and reset it as default after the join Locale locale = Locale.getDefault(); GeckoAppShell.loadGeckoLibs(getApplication().getPackageResourcePath()); Locale.setDefault(locale); Resources res = getBaseContext().getResources(); Configuration config = res.getConfiguration(); config.locale = locale; res.updateConfiguration(config, res.getDisplayMetrics()); } }); mLibLoadThread.start(); }
public void run() { Log.i(getClass().getSimpleName(), "Starting thread (run method started)"); boolean gameOverTriggered = false; long currentFrameIndex = 0; long currentFrameTimesAccumulated = 0; long lastLoopStartTime = System.currentTimeMillis(); // Debug.startMethodTracing( "escapePitTrace" ); // gameResult.status = GameResultStatus.RUNNING; loadFirstLevel(); if (orderedSubSystems == null) throw new IllegalStateException( "Cannot start a MainRunThread until you've loaded all SubSystems; try calling loadAllCoreSubSystems() first"); /** * ********************************************************************* START OF MAIN BODY OF * RUN LOOP ********************************************************************** */ while (myThread != null) { long loopStartTime = System.currentTimeMillis(); long lastFrameTime = loopStartTime - lastLoopStartTime; currentFrameTimesAccumulated += lastFrameTime; Canvas c = surfaceView.getHolder().lockCanvas(null); try { /** * Critical: lots of things in rendering depend on the size / shape of the Canvas; => we * must make sure the renderingSystem has the latest, current, correct Canvas before we do * anything else */ renderingSystem.canvas = c; for (SubSystem system : orderedSubSystems) { system.processOneGameTick(lastFrameTime); } synchronized (surfaceView.getHolder()) { renderingSystem.drawBackground(); renderingSystem.processOneGameTick(lastFrameTime); } Thread.sleep(5); } catch (GameOverError goe) { Log.i(getClass().getSimpleName(), "GameOver; killing thread"); myThread = null; Log.i(getClass().getSimpleName(), "GameOver; locking Entity System"); es.freeze(); gameOverTriggered = true; } catch (Throwable t) { Log.e( getClass().getSimpleName(), "Inside main draw loop, a major exception, killing draw thread:" + t); t.printStackTrace(); myThread = null; } finally { // ANDROID EXAMPLE CODE COMMENT: // do this in a finally so that if an exception is thrown // during the above, we don't leave the Surface in an // inconsistent state if (c != null) { surfaceView.getHolder().unlockCanvasAndPost(c); } currentFrameIndex++; lastLoopStartTime = loopStartTime; int frameTimesPerSample = 25; if (currentFrameIndex % frameTimesPerSample == 0) { // DEBUG: Log.i( getClass().getSimpleName(), "Averaged frame rate = " + // frameTimesPerSample * 1000 / currentFrameTimesAccumulated + " fps" ); currentFrameTimesAccumulated = 0; } } } // Debug.stopMethodTracing(); if (gameOverTriggered) { /** * Another bad design decision from the Android authors? This is not a great way to manage * inter-Activity communication (is there a better way?) */ Intent i = parentActivity.getIntent(); parentActivity.setResult(Activity.RESULT_OK, i); parentActivity.finish(); } Log.i( getClass().getSimpleName(), "Thread-stop COMPLETE: (run method expired; mythread was set to null)"); }