List of usage examples for android.os PowerManager newWakeLock
public WakeLock newWakeLock(int levelAndFlags, String tag)
From source file:com.TwentyCodes.android.IOIOTruck.NavigationActivity.java
/** * (non-Javadoc)/*from www.j a va2s .c o m*/ * @see android.support.v4.app.FragmentActivity#onResume() */ @Override protected void onResume() { super.onResume(); mMap = (MapFragment) this.getSupportFragmentManager().findFragmentById(R.id.map_fragment); mMap.setCompassListener(this); mMap.setGeoPointLocationListener(this); mMap.setLocationSelectedListener(this); mMap.setDirectionsCompleteListener(this); mMap.setRadius((int) (Debug.RADIUS * 1E3)); mMap.enableGPSProgess(); PowerManager pm = (PowerManager) this.getSystemService(Context.POWER_SERVICE); mWakeLock = pm.newWakeLock(PowerManager.SCREEN_DIM_WAKE_LOCK | PowerManager.ON_AFTER_RELEASE, TAG); mWakeLock.acquire(); }
From source file:org.openbmap.services.MasterBrainService.java
/** * Acquires wakelock to prevent CPU falling asleep *//*from w ww . j av a 2s .c o m*/ private void requirePowerLock() { final PowerManager mgr = (PowerManager) getSystemService(Context.POWER_SERVICE); try { Log.i(TAG, "Acquiring wakelock " + WAKELOCK_NAME); mWakeLock = mgr.newWakeLock(PowerManager.PARTIAL_WAKE_LOCK, WAKELOCK_NAME); mWakeLock.setReferenceCounted(true); } catch (final Exception e) { Log.e(TAG, "Error acquiring wakelock " + WAKELOCK_NAME + e.toString(), e); } }
From source file:uk.org.openseizuredetector.client.SdClientService.java
/** * onCreate() - called when services is created. Starts message * handler process to listen for messages from other processes. *///from w w w . j av a 2 s . com @Override public void onCreate() { Log.v(TAG, "onCreate()"); // FIXME - do we really need this for the client??? // Create a wake lock, but don't use it until the service is started. PowerManager powerManager = (PowerManager) getSystemService(POWER_SERVICE); mWakeLock = powerManager.newWakeLock(PowerManager.PARTIAL_WAKE_LOCK, "MyWakelockTag"); }
From source file:org.LK8000.LK8000.java
public void initSDL() { if (!Loader.loaded) return;/*from www . ja v a 2s. c o m*/ /* check if external storage is available; LK8000 doesn't work as long as external storage is being forwarded to a PC */ String state = Environment.getExternalStorageState(); Log.d(TAG, "getExternalStorageState() = " + state); if (!Environment.MEDIA_MOUNTED.equals(state)) { TextView tv = new TextView(this); tv.setText("External storage is not available (state='" + state + "'). Please turn off USB storage."); setContentView(tv); return; } nativeView = new NativeView(this, quitHandler, errorHandler); setContentView(nativeView); // Receive keyboard events nativeView.setFocusableInTouchMode(true); nativeView.setFocusable(true); nativeView.requestFocus(); // Obtain an instance of the Android PowerManager class PowerManager pm = (PowerManager) getSystemService(Context.POWER_SERVICE); // Create a WakeLock instance to keep the screen from timing out final String LKTAG = "LK8000:" + BuildConfig.BUILD_TYPE; wakeLock = pm.newWakeLock(PowerManager.PARTIAL_WAKE_LOCK | PowerManager.ACQUIRE_CAUSES_WAKEUP, LKTAG); // Activate the WakeLock wakeLock.acquire(); }
From source file:com.klinker.android.twitter.utils.NotificationUtils.java
public static void refreshNotification(Context context, boolean noTimeline) { AppSettings settings = AppSettings.getInstance(context); SharedPreferences sharedPrefs = context.getSharedPreferences( "com.klinker.android.twitter_world_preferences", Context.MODE_WORLD_READABLE + Context.MODE_WORLD_WRITEABLE); int currentAccount = sharedPrefs.getInt("current_account", 1); //int[] unreadCounts = new int[] {4, 1, 2}; // for testing int[] unreadCounts = getUnreads(context); int timeline = unreadCounts[0]; int realTimelineCount = timeline; // if they don't want that type of notification, simply set it to zero if (!settings.timelineNot || (settings.pushNotifications && settings.liveStreaming) || noTimeline) { unreadCounts[0] = 0;//ww w .ja v a2 s . c o m } if (!settings.mentionsNot) { unreadCounts[1] = 0; } if (!settings.dmsNot) { unreadCounts[2] = 0; } if (unreadCounts[0] == 0 && unreadCounts[1] == 0 && unreadCounts[2] == 0) { } else { Intent markRead = new Intent(context, MarkReadService.class); PendingIntent readPending = PendingIntent.getService(context, 0, markRead, 0); String shortText = getShortText(unreadCounts, context, currentAccount); String longText = getLongText(unreadCounts, context, currentAccount); // [0] is the full title and [1] is the screenname String[] title = getTitle(unreadCounts, context, currentAccount); boolean useExpanded = useExp(context); boolean addButton = addBtn(unreadCounts); if (title == null) { return; } Intent resultIntent; if (unreadCounts[1] != 0 && unreadCounts[0] == 0) { // it is a mention notification (could also have a direct message) resultIntent = new Intent(context, RedirectToMentions.class); } else if (unreadCounts[2] != 0 && unreadCounts[0] == 0 && unreadCounts[1] == 0) { // it is a direct message resultIntent = new Intent(context, RedirectToDMs.class); } else { resultIntent = new Intent(context, MainActivity.class); } PendingIntent resultPendingIntent = PendingIntent.getActivity(context, 0, resultIntent, 0); NotificationCompat.Builder mBuilder; Intent deleteIntent = new Intent(context, NotificationDeleteReceiverOne.class); mBuilder = new NotificationCompat.Builder(context).setContentTitle(title[0]) .setContentText(TweetLinkUtils.removeColorHtml(shortText, settings)) .setSmallIcon(R.drawable.ic_stat_icon).setLargeIcon(getIcon(context, unreadCounts, title[1])) .setContentIntent(resultPendingIntent).setAutoCancel(true) .setTicker(TweetLinkUtils.removeColorHtml(shortText, settings)) .setDeleteIntent(PendingIntent.getBroadcast(context, 0, deleteIntent, 0)) .setPriority(NotificationCompat.PRIORITY_HIGH); if (unreadCounts[1] > 1 && unreadCounts[0] == 0 && unreadCounts[2] == 0) { // inbox style notification for mentions mBuilder.setStyle(getMentionsInboxStyle(unreadCounts[1], currentAccount, context, TweetLinkUtils.removeColorHtml(shortText, settings))); } else if (unreadCounts[2] > 1 && unreadCounts[0] == 0 && unreadCounts[1] == 0) { // inbox style notification for direct messages mBuilder.setStyle(getDMInboxStyle(unreadCounts[1], currentAccount, context, TweetLinkUtils.removeColorHtml(shortText, settings))); } else { // big text style for an unread count on timeline, mentions, and direct messages mBuilder.setStyle(new NotificationCompat.BigTextStyle().bigText(Html.fromHtml( settings.addonTheme ? longText.replaceAll("FF8800", settings.accentColor) : longText))); } // Pebble notification if (sharedPrefs.getBoolean("pebble_notification", false)) { sendAlertToPebble(context, title[0], shortText); } // Light Flow notification sendToLightFlow(context, title[0], shortText); int homeTweets = unreadCounts[0]; int mentionsTweets = unreadCounts[1]; int dmTweets = unreadCounts[2]; int newC = 0; if (homeTweets > 0) { newC++; } if (mentionsTweets > 0) { newC++; } if (dmTweets > 0) { newC++; } if (settings.notifications && newC > 0) { if (settings.vibrate) { mBuilder.setDefaults(Notification.DEFAULT_VIBRATE); } if (settings.sound) { try { mBuilder.setSound(Uri.parse(settings.ringtone)); } catch (Exception e) { mBuilder.setSound(RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION)); } } if (settings.led) mBuilder.setLights(0xFFFFFF, 1000, 1000); // Get an instance of the NotificationManager service NotificationManagerCompat notificationManager = NotificationManagerCompat.from(context); if (addButton) { // the reply and read button should be shown Intent reply; if (unreadCounts[1] == 1) { reply = new Intent(context, NotificationCompose.class); } else { reply = new Intent(context, NotificationDMCompose.class); } Log.v("username_for_noti", title[1]); sharedPrefs.edit().putString("from_notification", "@" + title[1] + " " + title[2]).commit(); MentionsDataSource data = MentionsDataSource.getInstance(context); long id = data.getLastIds(currentAccount)[0]; PendingIntent replyPending = PendingIntent.getActivity(context, 0, reply, 0); sharedPrefs.edit().putLong("from_notification_long", id).commit(); sharedPrefs.edit() .putString("from_notification_text", "@" + title[1] + ": " + TweetLinkUtils.removeColorHtml(shortText, settings)) .commit(); // Create the remote input RemoteInput remoteInput = new RemoteInput.Builder(EXTRA_VOICE_REPLY) .setLabel("@" + title[1] + " ").build(); // Create the notification action NotificationCompat.Action replyAction = new NotificationCompat.Action.Builder( R.drawable.ic_action_reply_dark, context.getResources().getString(R.string.noti_reply), replyPending).addRemoteInput(remoteInput).build(); NotificationCompat.Action.Builder action = new NotificationCompat.Action.Builder( R.drawable.ic_action_read_dark, context.getResources().getString(R.string.mark_read), readPending); mBuilder.addAction(replyAction); mBuilder.addAction(action.build()); } else { // otherwise, if they can use the expanded notifications, the popup button will be shown Intent popup = new Intent(context, RedirectToPopup.class); popup.addFlags(Intent.FLAG_ACTIVITY_SINGLE_TOP | Intent.FLAG_ACTIVITY_NEW_TASK); popup.putExtra("from_notification", true); PendingIntent popupPending = PendingIntent.getActivity(context, 0, popup, 0); NotificationCompat.Action.Builder action = new NotificationCompat.Action.Builder( R.drawable.ic_popup, context.getResources().getString(R.string.popup), popupPending); mBuilder.addAction(action.build()); } // Build the notification and issues it with notification manager. notificationManager.notify(1, mBuilder.build()); // if we want to wake the screen on a new message if (settings.wakeScreen) { PowerManager pm = (PowerManager) context.getSystemService(Context.POWER_SERVICE); final PowerManager.WakeLock wakeLock = pm.newWakeLock((PowerManager.SCREEN_BRIGHT_WAKE_LOCK | PowerManager.FULL_WAKE_LOCK | PowerManager.ACQUIRE_CAUSES_WAKEUP), "TAG"); wakeLock.acquire(5000); } } // if there are unread tweets on the timeline, check them for favorite users if (settings.favoriteUserNotifications && realTimelineCount > 0) { favUsersNotification(currentAccount, context); } } try { ContentValues cv = new ContentValues(); cv.put("tag", "com.klinker.android.twitter/com.klinker.android.twitter.ui.MainActivity"); // add the direct messages and mentions cv.put("count", unreadCounts[1] + unreadCounts[2]); context.getContentResolver().insert(Uri.parse("content://com.teslacoilsw.notifier/unread_count"), cv); } catch (IllegalArgumentException ex) { /* Fine, TeslaUnread is not installed. */ } catch (Exception ex) { /* Some other error, possibly because the format of the ContentValues are incorrect. Log but do not crash over this. */ ex.printStackTrace(); } }
From source file:com.elekso.potfix.MainActivity.java
@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); PowerManager pm = (PowerManager) getApplicationContext() .getSystemService(getApplicationContext().POWER_SERVICE); PowerManager.WakeLock wl = pm.newWakeLock(PowerManager.PARTIAL_WAKE_LOCK, " POTFIX holding wake lock"); wl.acquire();/* w w w . jav a 2s . c o m*/ Globals.getInstance().setFlexiblemap(true); // // // new Thread(new Runnable(){ // @Override // public void run() { // try { // LALpotfixservicePortBinding service = new LALpotfixservicePortBinding(); // try { // globaldata_test=service.CheckWS("mandar"); // // } catch (Exception e) { // e.printStackTrace(); // } // } catch (Exception ex) { // ex.printStackTrace(); // } // } // }).start(); String login = ""; // Config.getInstance(getBaseContext(),getCacheDir()).setProfile("df","asd"); login = Config.getInstance(getBaseContext(), getCacheDir()).getProfileName(); if (login == null || login.isEmpty()) { Intent intent = new Intent(this, LoginActivity.class); startActivity(intent); return; } //remove // Stetho.initializeWithDefaults(this); // Toolbar Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar); setSupportActionBar(toolbar); // Drawer drawer = (DrawerLayout) findViewById(R.id.drawer_layout); ActionBarDrawerToggle toggle = new ActionBarDrawerToggle(this, drawer, toolbar, R.string.navigation_drawer_open, R.string.navigation_drawer_close); drawer.setDrawerListener(toggle); toggle.syncState(); tusername = (TextView) drawer.findViewById(R.id.tvusername); // tuseremail =(TextView) findViewById(R.id.tvuseremail); // // if(login!=null) // tusername.setText("jhjhjhjh"); // if(Config.getInstance().getProfileEmail()!=null) //tuseremail.setText(Config.getInstance().getProfileEmail()); // FAB fab = (FloatingActionButton) findViewById(R.id.fab); fab.setRippleColor(Color.parseColor("#78D6F3")); fab.setBackgroundTintList(ColorStateList.valueOf(Color.parseColor("#039FDC"))); fab.setImageResource(R.drawable.ic_gps_fixed_white_24dp); fab.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View view) { switch (currentFragment) { case 1: //profile Snackbar.make(view, "Updating Information", Snackbar.LENGTH_LONG).setAction("Action", null) .show(); Fragment frg = new ProfileFragment(); FragmentTransaction transaction = getSupportFragmentManager().beginTransaction(); transaction.replace(R.id.frame_containerone, frg); transaction.setTransition(FragmentTransaction.TRANSIT_FRAGMENT_OPEN); transaction.commit(); break; case 2: //map if (Globals.getInstance().getFlexiblemap()) { Snackbar.make(view, "Free to Scroll", Snackbar.LENGTH_LONG).setAction("Action", null) .show(); Globals.getInstance().setFlexiblemap(false); fab.setRippleColor(Color.parseColor("#FFE082")); fab.setBackgroundTintList(ColorStateList.valueOf(Color.parseColor("#FFB300"))); fab.setImageResource(R.drawable.ic_gps_off_white_24dp); } else { Snackbar.make(view, "Follow Potfix", Snackbar.LENGTH_LONG).setAction("Action", null).show(); Globals.getInstance().setFlexiblemap(true); fab.setRippleColor(Color.parseColor("#78D6F3")); fab.setBackgroundTintList(ColorStateList.valueOf(Color.parseColor("#039FDC"))); fab.setImageResource(R.drawable.ic_gps_fixed_white_24dp); } break; case 3: //share //Snackbar.make(view, "Some sharing action", Snackbar.LENGTH_LONG).setAction("Action", null).show(); String[] TO = { "aziz@potfix.com" }; String[] CC = { "" }; Intent emailIntent = new Intent(Intent.ACTION_SEND); emailIntent.setData(Uri.parse("mailto:")); emailIntent.setType("text/plain"); emailIntent.putExtra(Intent.EXTRA_EMAIL, TO); emailIntent.putExtra(Intent.EXTRA_CC, CC); emailIntent.putExtra(Intent.EXTRA_SUBJECT, "Potfix Communication"); emailIntent.putExtra(Intent.EXTRA_TEXT, "Email message..."); try { startActivity(Intent.createChooser(emailIntent, "Send mail...")); finish(); } catch (android.content.ActivityNotFoundException ex) { Toast.makeText(MainActivity.this, "There is no email client installed.", Toast.LENGTH_SHORT) .show(); } break; case 4: //legal Snackbar.make(view, "Software License", Snackbar.LENGTH_LONG).setAction("Action", null).show(); drawer.openDrawer(Gravity.LEFT); break; } } }); NavigationView navigationView = (NavigationView) findViewById(R.id.nav_view); navigationView.setNavigationItemSelectedListener(this); startService(new Intent(getBaseContext(), BackgroundService.class)); FragmentTransaction mTransaction = getSupportFragmentManager().beginTransaction(); MapsFragment mFRaFragment = new MapsFragment(); mTransaction.add(R.id.frame_containerone, mFRaFragment); mTransaction.commit(); LocationManager locationManager = (LocationManager) getSystemService(LOCATION_SERVICE); if (locationManager.isProviderEnabled(LocationManager.GPS_PROVIDER)) { Toast.makeText(this, "GPS is Enabled in your devide", Toast.LENGTH_SHORT).show(); } else { showGPSDisabledAlertToUser(); } // if (locationManager.isProviderEnabled(LocationManager.NETWORK_PROVIDER)){ // Toast.makeText(this, "Network is Enabled in your devide", Toast.LENGTH_SHORT).show(); // }else{ // showNetDisabledAlertToUser(); // } createNotification(); }
From source file:com.ternup.caddisfly.fragment.ResultFragment.java
public void postResult(final String url) { RequestParams params = new RequestParams(); TimeZone tz = TimeZone.getTimeZone("UTC"); final DateFormat df = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm'Z'"); df.setTimeZone(tz);/* ww w .jav a 2 s . c o m*/ final ArrayList<String> filePaths = FileUtils.getFilePaths(getActivity(), folderName, "/small/", mLocationId); File myFile = new File(filePaths.get(0)); String date = df.format(DateUtils.getDateFromFilename(myFile.getName())); params.put("date", date); String deviceId = Build.MANUFACTURER + " " + Build.MODEL; if (deviceId.length() > 32) { deviceId = deviceId.substring(1, 32); } params.put("deviceId", deviceId); params.put("type", String.valueOf(mTestTypeId + 1)); if (wakeLock == null || !wakeLock.isHeld()) { PowerManager pm = (PowerManager) getActivity().getApplicationContext() .getSystemService(Context.POWER_SERVICE); wakeLock = pm.newWakeLock(PowerManager.FULL_WAKE_LOCK | PowerManager.ACQUIRE_CAUSES_WAKEUP | PowerManager.ON_AFTER_RELEASE, "MyWakeLock"); wakeLock.acquire(); } WebClient.post("tests", params, new AsyncHttpResponseHandler() { @Override public void onSuccess(int statusCode, Header[] headers, byte[] responseBody) { String response = responseBody == null ? null : new String(responseBody); try { JSONObject json = new JSONObject(response); final int newId = json.getInt("id"); if (filePaths.size() > 0) { count = 0; totalCount = filePaths.size(); postItem(newId, filePaths); } } catch (JSONException e) { e.printStackTrace(); } } @Override public void onFailure(int statusCode, Header[] headers, byte[] responseBody, Throwable error) { Log.d(Globals.DEBUG_TAG, "fail: " + error.getMessage()); getActivity().runOnUiThread(new Runnable() { public void run() { if (progressDialog != null) { progressDialog.dismiss(); } if (wakeLock != null && wakeLock.isHeld()) { wakeLock.release(); } } }); } }); }
From source file:com.keithcassidy.finishline.FinishLineService.java
private void acquireWakeLock() { try {//from w w w . ja v a2 s . c o m PowerManager powerManager = (PowerManager) getSystemService(Context.POWER_SERVICE); if (powerManager == null) { Log.e(TAG, "powerManager is null."); return; } if (wakeLock == null) { wakeLock = powerManager.newWakeLock(PowerManager.PARTIAL_WAKE_LOCK, TAG); if (wakeLock == null) { Log.e(TAG, "wakeLock is null."); return; } } if (!wakeLock.isHeld()) { wakeLock.acquire(); if (!wakeLock.isHeld()) { Log.e(TAG, "Unable to hold wakeLock."); } } } catch (RuntimeException e) { Log.e(TAG, "Caught RuntimeException exception in acquireWakeLock", e); } }
From source file:com.intel.RtcPingDownloadTester.java
@Override protected void onCreate(Bundle savedInstanceState) { /** First, call the superclass onCreate method */ super.onCreate(savedInstanceState); Log.v(TAG, "onCreate: " + savedInstanceState); PowerManager pm = (PowerManager) getSystemService(Context.POWER_SERVICE); mWakeLock = pm.newWakeLock(PowerManager.PARTIAL_WAKE_LOCK, "RtcPingDownloadTester"); nWakeLock = pm.newWakeLock(PowerManager.PARTIAL_WAKE_LOCK, "RtcPingDownloadTester2"); setContentView(R.layout.main);/*w ww . j a v a2 s . c o m*/ b_Start = (Button) this.findViewById(R.id.ok); b_Start.setOnClickListener(new OnClickListener() { /* Start button pressed handler.*/ public void onClick(View v) { Log.v(TAG, "onClick : START"); /* a bit of sanity checking..*/ if (nRepeatTimerEntry < 0) nRepeatTimerEntry = 0; else if (nRepeatTimerEntry > 600) nRepeatTimerEntry = 600; /* Entry point for alarm task */ if ((nRepeatTimerEntry != 0) && (is_running == false)) { is_running = true; string_curr_state = "RUNNING"; label_curr_state.setText(string_curr_state); registerReceiver(alarmReceiver, myFilter); new setAlarmTask().execute(nRepeatTimerEntry * 1000); } } }); b_Stop = (Button) this.findViewById(R.id.stop); b_Stop.setOnClickListener(new OnClickListener() { /* Stop button pressed handler*/ public void onClick(View v) { Log.v(TAG, "onClick : STOP"); if (is_running) { unregisterReceiver(alarmReceiver); is_running = false; string_curr_state = "STOPED"; label_curr_state.setText(string_curr_state); clearAlarm(); } } }); label_curr_state = (TextView) this.findViewById(R.id.label_curr_state); label_curr_state.setText(string_curr_state); label_console_box = (TextView) this.findViewById(R.id.label_console_box); label_console_box.setText(string_console_text); textBox_TimerEntry = (EditText) this.findViewById(R.id.textBox_1); textBox_TimerEntry.setText(String.valueOf(nRepeatTimerEntry), TextView.BufferType.EDITABLE); textBox_TimerEntry.addTextChangedListener(textBox_TimerEntry_EditorWatcher); textBox_HostIp = (EditText) this.findViewById(R.id.textBox_2); textBox_HostIp.setText(host_ip_addr, TextView.BufferType.EDITABLE); textBox_HostIp.addTextChangedListener(textBox_HostIp_EditorWatcher); textBox_fileUrl = (EditText) this.findViewById(R.id.textBox_3); textBox_fileUrl.setText(fileUrl, TextView.BufferType.EDITABLE); textBox_fileUrl.addTextChangedListener(textBox_fileUrl_EditorWatcher); textBox_wklk = (EditText) this.findViewById(R.id.textBox_4); textBox_wklk.setText(String.valueOf(wklk), TextView.BufferType.EDITABLE); textBox_wklk.addTextChangedListener(textBox_wklk_EditorWatcher); checkBox_1 = (CheckBox) this.findViewById(R.id.checkBox_1); checkBox_1.setChecked(ping_enabled); checkBox_1.setOnClickListener(new OnClickListener() { /* Ping checkbox handler */ public void onClick(View v) { if (((CheckBox) v).isChecked()) ping_enabled = true; else ping_enabled = false; } }); checkBox_2 = (CheckBox) this.findViewById(R.id.checkBox_2); checkBox_2.setChecked(download_enabled); checkBox_2.setOnClickListener(new OnClickListener() { /* Download checkbox handler */ public void onClick(View v) { if (((CheckBox) v).isChecked()) download_enabled = true; else download_enabled = false; } }); checkBox_3 = (CheckBox) this.findViewById(R.id.checkBox_3); checkBox_3.setChecked(wklk_enabled); checkBox_3.setOnClickListener(new OnClickListener() { /* Download checkbox handler */ public void onClick(View v) { if (((CheckBox) v).isChecked()) wklk_enabled = true; else wklk_enabled = false; } }); }
From source file:cm.aptoide.pt.Aptoide.java
@Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); PowerManager powerManager = (PowerManager) getSystemService(Context.POWER_SERVICE); keepScreenOn = powerManager.newWakeLock(PowerManager.SCREEN_DIM_WAKE_LOCK | PowerManager.ON_AFTER_RELEASE, "Full Power"); DownloadQueueServiceIntent = new Intent(getApplicationContext(), DownloadQueueService.class); startService(DownloadQueueServiceIntent); //@dsilveira #534 +10lines Check if Aptoide is already running to avoid wasting time and showing the splash ActivityManager activityManager = (ActivityManager) getApplicationContext() .getSystemService(Context.ACTIVITY_SERVICE); List<RunningTaskInfo> running = activityManager.getRunningTasks(Integer.MAX_VALUE); for (RunningTaskInfo runningTask : running) { if (runningTask.baseActivity.getClassName().equals("cm.aptoide.pt.RemoteInTab")) { //RemoteInTab is the real Aptoide Activity Message msg = new Message(); msg.what = LOAD_TABS;/*w w w. ja v a 2 s . co m*/ startHandler.sendMessage(msg); return; } } Log.d("Aptoide", "******* \n Downloads will be made to: " + Environment.getExternalStorageDirectory().getPath() + "\n ********"); sPref = getSharedPreferences("aptoide_prefs", MODE_PRIVATE); prefEdit = sPref.edit(); db = new DbHandler(this); PackageManager mPm = getPackageManager(); try { pkginfo = mPm.getPackageInfo("cm.aptoide.pt", 0); } catch (NameNotFoundException e) { } requestWindowFeature(Window.FEATURE_NO_TITLE); getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN, WindowManager.LayoutParams.FLAG_FULLSCREEN); try { if (pkginfo.versionCode < Integer.parseInt(getXmlElement("versionCode"))) { Log.d("Aptoide-VersionCode", "Using version " + pkginfo.versionCode + ", suggest update!"); requestUpdateSelf(); } else { proceed(); } } catch (Exception e) { e.printStackTrace(); proceed(); } }