Example usage for android.os PowerManager SCREEN_DIM_WAKE_LOCK

List of usage examples for android.os PowerManager SCREEN_DIM_WAKE_LOCK

Introduction

In this page you can find the example usage for android.os PowerManager SCREEN_DIM_WAKE_LOCK.

Prototype

int SCREEN_DIM_WAKE_LOCK

To view the source code for android.os PowerManager SCREEN_DIM_WAKE_LOCK.

Click Source Link

Document

Wake lock level: Ensures that the screen is on (but may be dimmed); the keyboard backlight will be allowed to go off.

Usage

From source file:com.terminal.ide.TermService.java

@Override
public void onCreate() {
    compat = new ServiceForegroundCompat(this);
    mTermSessions = new ArrayList<TermSession>();

    /**//from   w w w  . ja  v a  2  s .com
     * ??
     * @author wanghao
     * @date 2015-3-27
     * ???Activity
     */
    //?intent
    //warning??start.class
    //?mainActivity
    Intent openMainActivityIntent = new Intent(this, mainAvtivity.class);
    Intent openTerminalActivityIntent = new Intent(this, Term.class);
    openTerminalActivityIntent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
    openMainActivityIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
    Intent exitTerminalIntent = new Intent(this, ExitService.class);
    Notification sessionBuilder = new NotificationCompat.Builder(this).setSmallIcon(R.drawable.ic_launcher)
            .setContentTitle(getText(R.string.application_terminal))
            .setContentText(getText(R.string.service_notify_text))
            .setContentIntent(PendingIntent.getActivity(this, 0, openMainActivityIntent, 0))
            .setStyle(new NotificationCompat.BigTextStyle().bigText(getText(R.string.service_notify_text)))
            .addAction(R.drawable.ic_action_iconfont_terminal, getText(R.string.notification_open_termianl),
                    PendingIntent.getActivity(this, 0, openTerminalActivityIntent,
                            Intent.FLAG_ACTIVITY_CLEAR_TOP))
            .addAction(R.drawable.ic_action_iconfont_exit, getText(R.string.notification_exit_app),
                    PendingIntent.getService(this, 0, exitTerminalIntent, 0))
            .setOngoing(true).build();
    compat.startForeground(RUNNING_NOTIFICATION, sessionBuilder);

    mPrefs = PreferenceManager.getDefaultSharedPreferences(this);
    mPrefs.registerOnSharedPreferenceChangeListener(this);
    mHardKeys.setKeyMappings(mPrefs);

    //Setup the Hard Key Mappings..
    mSettings = new TermSettings(mPrefs);

    //Need to set the HOME Folder and Bash startup..
    //Sometime getfilesdir return NULL ?
    mSessionInit = false;
    File home = getFilesDir();
    if (home != null) {
        initSessions(home);
    }

    //Start a webserver for comms..
    //        mServer = new webserver(this);
    //        mServer.start();

    PowerManager pm = (PowerManager) getSystemService(Context.POWER_SERVICE);
    WifiManager wm = (WifiManager) getSystemService(Context.WIFI_SERVICE);

    //Get a wake lock
    mWakeLock = pm.newWakeLock(PowerManager.PARTIAL_WAKE_LOCK, TermDebug.LOG_TAG);
    mScreenLock = pm.newWakeLock(PowerManager.SCREEN_DIM_WAKE_LOCK, TermDebug.LOG_TAG);
    mWifiLock = wm.createWifiLock(WifiManager.WIFI_MODE_FULL, TermDebug.LOG_TAG);

    //Get the Initial Values
    //        boolean cpulock     = getStringPref("cpulock","1") == 1 ? true : false;
    //        boolean wifilock    = getStringPref("wifilock","0") == 1 ? true : false;
    //        boolean screenlock  = getStringPref("screenlock","0") == 1 ? true : false;
    setupWakeLocks();

    Log.d(TermDebug.LOG_TAG, "TermService started");

    return;
}

From source file:eu.chainfire.opendelta.UpdateService.java

@SuppressWarnings("deprecation")
@Override/*from   www  .  j  a  va 2s. c  om*/
public void onCreate() {
    super.onCreate();

    config = Config.getInstance(this);

    wakeLock = ((PowerManager) getSystemService(POWER_SERVICE)).newWakeLock(
            config.getKeepScreenOn() ? PowerManager.SCREEN_DIM_WAKE_LOCK | PowerManager.ACQUIRE_CAUSES_WAKEUP
                    : PowerManager.PARTIAL_WAKE_LOCK,
            "OpenDelta WakeLock");
    wifiLock = ((WifiManager) getSystemService(WIFI_SERVICE)).createWifiLock(WifiManager.WIFI_MODE_FULL,
            "OpenDelta WifiLock");

    handlerThread = new HandlerThread("OpenDelta Service Thread");
    handlerThread.start();
    handler = new Handler(handlerThread.getLooper());

    notificationManager = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);
    prefs = PreferenceManager.getDefaultSharedPreferences(this);

    scheduler = new Scheduler(this, this);

    networkState = new NetworkState();
    networkState.start(this, this,
            prefs.getInt(PREF_AUTO_UPDATE_NETWORKS_NAME, PREF_AUTO_UPDATE_NETWORKS_DEFAULT));

    batteryState = new BatteryState();
    batteryState.start(this, this, 50, true);

    screenState = new ScreenState();
    screenState.start(this, this);

    prefs.registerOnSharedPreferenceChangeListener(this);

    autoState();
}

From source file:com.parttime.activity.ChatActivity.java

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    requestWindowFeature(Window.FEATURE_NO_TITLE);
    setContentView(R.layout.chat);/*  w w w . ja v  a2  s  .c om*/

    mContext = this;
    toChatUsername = getIntent().getStringExtra("userid");
    //       if(toChatUsername==null)
    //       {
    //          toChatUsername="";
    //       }
    flag = getIntent().getStringExtra("flag");
    if (flag != null && flag.equals("commnuication")) {
        Utils.CommitPageFlagToShared(this, Constant.FINISH_ACTIVITY_FLAG_COMMUNICATION);
    }

    Utils.HxUserNames.add(toChatUsername);
    initView();
    iv_emoticons_normal.setOnClickListener(this);
    iv_emoticons_checked.setOnClickListener(this);
    // position = getIntent().getIntExtra("position", -1);
    clipboard = (ClipboardManager) getSystemService(Context.CLIPBOARD_SERVICE);
    manager = (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE);
    getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_ALWAYS_HIDDEN);
    wakeLock = ((PowerManager) getSystemService(Context.POWER_SERVICE))
            .newWakeLock(PowerManager.SCREEN_DIM_WAKE_LOCK, "demo");
    conversation = EMChatManager.getInstance().getConversation(toChatUsername);
    // ?0
    conversation.resetUnreadMsgCount();
    adapter = new MessageAdapter(this, toChatUsername, chatType);
    // ?
    listView.setAdapter(adapter);

    listView.setOnScrollListener(new ListScrollListener());
    int count = listView.getCount();
    if (count > 0) {
        listView.setSelection(count - 1);
    }

    listView.setOnTouchListener(new OnTouchListener() {

        @Override
        public boolean onTouch(View v, MotionEvent event) {
            hideKeyboard();
            more.setVisibility(View.GONE);
            iv_emoticons_normal.setVisibility(View.VISIBLE);
            iv_emoticons_checked.setVisibility(View.INVISIBLE);
            emojiIconContainer.setVisibility(View.GONE);
            btnContainer.setVisibility(View.GONE);
            return false;
        }
    });
    // ?
    receiver = new NewMessageBroadcastReceiver();
    IntentFilter intentFilter = new IntentFilter(EMChatManager.getInstance().getNewMessageBroadcastAction());
    // Mainacitivity,??chat??????
    intentFilter.setPriority(5);
    registerReceiver(receiver, intentFilter);

    // ack?BroadcastReceiver
    IntentFilter ackMessageIntentFilter = new IntentFilter(
            EMChatManager.getInstance().getAckMessageBroadcastAction());
    ackMessageIntentFilter.setPriority(5);
    registerReceiver(ackMessageReceiver, ackMessageIntentFilter);

    // ??BroadcastReceiver
    IntentFilter deliveryAckMessageIntentFilter = new IntentFilter(
            EMChatManager.getInstance().getDeliveryAckMessageBroadcastAction());
    deliveryAckMessageIntentFilter.setPriority(5);
    registerReceiver(deliveryAckMessageReceiver, deliveryAckMessageIntentFilter);

    // show forward message if the message is not null
    String forward_msg_id = getIntent().getStringExtra("forward_msg_id");
    if (forward_msg_id != null) {
        // ?????
        forwardMessage(forward_msg_id);
    }

    // setUpView();
}

From source file:com.sentaroh.android.SMBExplorer.FileIo.java

@SuppressWarnings("deprecation")
@Override/*from   www.  j  a  v a 2  s  .  c om*/
public void run() {
    sendLogMsg("I", "Task has started.");

    final WakeLock wake_lock = ((PowerManager) mContext.getSystemService(Context.POWER_SERVICE))
            .newWakeLock(PowerManager.SCREEN_DIM_WAKE_LOCK | PowerManager.ACQUIRE_CAUSES_WAKEUP
    //                         | PowerManager.ON_AFTER_RELEASE
                    , "SMBExplorer-ScreenOn");
    final WifiLock wifi_lock = ((WifiManager) mContext.getSystemService(Context.WIFI_SERVICE))
            .createWifiLock(WifiManager.WIFI_MODE_FULL, "SMBExplorer-wifi");

    if (mGp.fileIoWakeLockRequired)
        wake_lock.acquire();
    if (mGp.fileIoWifiLockRequired)
        wifi_lock.acquire();

    try {
        if (fileIoArea == null)
            fileIoArea = new byte[SMB_BUFF_SIZE];//4096*64];

        taskBeginTime = System.currentTimeMillis();

        waitMediaScanner(true);

        boolean fileioTaskResultOk = false;
        for (int i = 0; i < fileioLinkParm.size(); i++) {
            fileioTaskResultOk = fileOperation(fileioLinkParm.get(i));
            if (!fileioTaskResultOk)
                break;
        }
        sendLogMsg("I", "Task was ended. fileioTaskResultOk=" + fileioTaskResultOk + ", fileioThreadCtrl:"
                + fileioThreadCtrl.toString());
        sendLogMsg("I", "Task elapsed time=" + (System.currentTimeMillis() - taskBeginTime));
        if (fileioTaskResultOk) {
            fileioThreadCtrl.setThreadResultSuccess();
            sendDebugLogMsg(1, "I", "Task was endeded without error.");
        } else if (fileioThreadCtrl.isEnabled()) {
            fileioThreadCtrl.setThreadResultError();
            sendLogMsg("W", "Task was ended with error.");
        } else {
            fileioThreadCtrl.setThreadResultCancelled();
            sendLogMsg("W", "Task was cancelled.");
        }
        fileioThreadCtrl.setDisabled();
        mediaScanner.disconnect();
        waitMediaScanner(false);

        uiHandler.post(new Runnable() {// UI thread
            @Override
            public void run() {
                notifyEvent.notifyToListener(true, null);
            }
        });
    } finally {
        if (wake_lock.isHeld())
            wake_lock.release();
        if (wifi_lock.isHeld())
            wifi_lock.release();
    }
}

From source file:cm.aptoide.pt.services.ServiceDownloadManager.java

@Override
public void onCreate() {
    if (!isRunning) {
        PowerManager powerManager = (PowerManager) getSystemService(Context.POWER_SERVICE);
        keepScreenOn = powerManager//  w ww  .  ja  v a 2  s  .  c  o  m
                .newWakeLock(PowerManager.SCREEN_DIM_WAKE_LOCK | PowerManager.ON_AFTER_RELEASE, "Full Power");

        ongoingDownloads = new HashMap<Integer, ViewDownloadManagement>();
        completedDownloads = new HashMap<Integer, ViewDownloadManagement>();
        failedDownloads = new HashMap<Integer, ViewDownloadManagement>();

        globaDownloadStatus = new ViewDownload("local:\\GLOBAL");

        cachedThreadPool = Executors.newCachedThreadPool();

        helperDownload = new HelperDownload(this);
        isRunning = true;
    }
    super.onCreate();
}

From source file:com.sentaroh.android.SMBSync.SMBSyncMain.java

/** Called when the activity is first created. */
@Override/*from  www .  jav a  2  s  .c  o m*/
public void onCreate(Bundle savedInstanceState) {
    //      StrictMode.enableDefaults();
    //      setTheme(android.R.style.Theme_Dialog);
    //      setTheme(android.R.style.Theme_Holo_Light);
    //      setTheme(android.R.style.Theme_Light);
    super.onCreate(savedInstanceState);
    //      requestWindowFeature(Window.FEATURE_NO_TITLE);

    mCurrentLocal = getResources().getConfiguration().locale;

    setContentView(R.layout.main);
    mContext = this;
    mGp = (GlobalParameters) getApplication();
    mGp.enableMainUi = true;
    mGp.uiHandler = new Handler();
    mGp.SMBSync_External_Root_Dir = LocalMountPoint.getExternalStorageDir();

    startService(new Intent(mContext, SMBSyncService.class));

    mDimScreenWakelock = ((PowerManager) getSystemService(Context.POWER_SERVICE))
            .newWakeLock(PowerManager.SCREEN_DIM_WAKE_LOCK
                    //                    PowerManager.PARTIAL_WAKE_LOCK
                    | PowerManager.ACQUIRE_CAUSES_WAKEUP
    //                         | PowerManager.ON_AFTER_RELEASE
                    , "SMBSync-ScreenOn");

    mWifiLock = ((WifiManager) mContext.getSystemService(Context.WIFI_SERVICE))
            .createWifiLock(WifiManager.WIFI_MODE_FULL, "SMBSync-wifi");

    if (tcService == null)
        tcService = new ThreadCtrl();

    //      if (Build.VERSION.SDK_INT>=14)
    //         this.getActionBar().setHomeButtonEnabled(false);

    if (util == null)
        util = new SMBSyncUtil(this.getApplicationContext(), "Main", mGp);
    util.setActivityIsForeground(true);

    if (ccMenu == null)
        ccMenu = new CustomContextMenu(getResources(), getSupportFragmentManager());
    commonDlg = new CommonDialog(mContext, getSupportFragmentManager());

    createTabView();
    loadMsgString();
    initSettingsParms();
    applySettingParms();
    initJcifsOption();

    checkExternalStorage();
    mGp.SMBSync_Internal_Root_Dir = getFilesDir().toString();

    util.openLogFile();

    initAdapterAndView();

    util.addDebugLogMsg(1, "I", "onCreate entered, " + "resartStatus=" + restartStatus
            + ", isActivityForeground=" + util.isActivityForeground());

    getApplVersionName();

    if (profMaint == null)
        profMaint = new ProfileMaintenance(util, this, commonDlg, ccMenu, mGp);

    SchedulerMain.setTimer(mContext, SCHEDULER_INTENT_SET_TIMER_IF_NOT_SET);
}

From source file:at.alladin.rmbt.android.test.RMBTLoopService.java

@Override
public void onCreate() {
    Log.d(TAG, "created");
    super.onCreate();

    partialWakeLock = ((PowerManager) getApplicationContext().getSystemService(Context.POWER_SERVICE))
            .newWakeLock(PowerManager.PARTIAL_WAKE_LOCK, "RMBTLoopWakeLock");
    partialWakeLock.acquire();/*from w  ww. ja va2 s  . c om*/

    alarmManager = (AlarmManager) getSystemService(ALARM_SERVICE);
    notificationManager = (NotificationManager) getSystemService(NOTIFICATION_SERVICE);

    readConfig();

    geoLocation = new LocalGeoLocation(this);
    geoLocation.start();

    notificationBuilder = createNotificationBuilder();

    startForeground(NotificationIDs.LOOP_ACTIVE, notificationBuilder.build());
    final IntentFilter actionFilter = new IntentFilter(RMBTService.BROADCAST_TEST_FINISHED);
    actionFilter.addAction(RMBTService.BROADCAST_TEST_ABORTED);
    registerReceiver(receiver, actionFilter);

    final IntentFilter rmbtTaskActionFilter = new IntentFilter(RMBTTask.BROADCAST_TEST_START);
    registerReceiver(rmbtTaskReceiver, rmbtTaskActionFilter);

    final Intent alarmIntent = new Intent(ACTION_ALARM, null, this, getClass());
    alarm = PendingIntent.getService(this, 0, alarmIntent, 0);

    if (ConfigHelper.isLoopModeWakeLock(this)) {
        Log.d(TAG, "using dimWakeLock");
        dimWakeLock = ((PowerManager) getApplicationContext().getSystemService(Context.POWER_SERVICE))
                .newWakeLock(PowerManager.SCREEN_DIM_WAKE_LOCK | PowerManager.ACQUIRE_CAUSES_WAKEUP
                        | PowerManager.ON_AFTER_RELEASE, "RMBTLoopDimWakeLock");
        dimWakeLock.acquire();

        final Intent wakeupAlarmIntent = new Intent(ACTION_WAKEUP_ALARM, null, this, getClass());
        wakeupAlarm = PendingIntent.getService(this, 0, wakeupAlarmIntent, 0);

        final long now = SystemClock.elapsedRealtime();
        alarmManager.setRepeating(AlarmManager.ELAPSED_REALTIME_WAKEUP, now + 10000, 10000, wakeupAlarm);
    }

    bindService(new Intent(getApplicationContext(), RMBTService.class), this, BIND_AUTO_CREATE);
}

From source file:com.easemob.chatuidemo.activity.BaseChatActivity.java

private void setUpView() {
    iv_emoticons_normal.setOnClickListener(this);
    iv_emoticons_checked.setOnClickListener(this);
    // position = getIntent().getIntExtra("position", -1);
    clipboard = (ClipboardManager) getSystemService(Context.CLIPBOARD_SERVICE);
    manager = (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE);
    getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_ALWAYS_HIDDEN);
    wakeLock = ((PowerManager) getSystemService(Context.POWER_SERVICE))
            .newWakeLock(PowerManager.SCREEN_DIM_WAKE_LOCK, "demo");
    // ???/*from w  w  w  . j  a  v a  2 s  .com*/
    chatType = getIntent().getIntExtra("chatType", CHATTYPE_SINGLE);

    if (chatType == CHATTYPE_SINGLE) { // ??
        toChatUsername = getIntent().getStringExtra("userId");
        Map<String, RobotUser> robotMap = ((DemoHXSDKHelper) HXSDKHelper.getInstance()).getRobotList();
        if (robotMap != null && robotMap.containsKey(toChatUsername)) {
            isRobot = true;
            String nick = robotMap.get(toChatUsername).getNick();
            if (!TextUtils.isEmpty(nick)) {
                setName(nick);
            } else {
                setName(toChatUsername);
            }
        } else {
            setName(toChatUsername);
        }
    }

    onConversationInit();
    onListViewCreation();
}

From source file:com.smc.tw.waltz.MainActivity.java

@Override
protected void onCreate(Bundle savedInstanceState) {
    if (DEBUG)//from   www  .  j  av a2  s  .  c  om
        Log.d(TAG, "onCreate");

    overridePendingTransition(R.anim.slide_right_in, R.anim.slide_left_out);

    super.onCreate(savedInstanceState);

    Fabric.with(this, new Crashlytics());

    setContentView(R.layout.activity_main);

    mPowerManager = (PowerManager) getSystemService(Context.POWER_SERVICE);
    mAudioManager = (AudioManager) getSystemService(Context.AUDIO_SERVICE);

    mWakeLock = mPowerManager.newWakeLock(PowerManager.SCREEN_DIM_WAKE_LOCK, TAG);

    mPreferences = PreferenceManager.getDefaultSharedPreferences(this);

    mFragmentManager = getSupportFragmentManager();

    setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT);

    mAudioRecordBufferSize = 5600;//AudioRecord.getMinBufferSize(8000, AudioFormat.CHANNEL_IN_MONO, AudioFormat.ENCODING_PCM_16BIT)*10;
    mAudioRecord = new AudioRecord(MediaRecorder.AudioSource.MIC, 8000, AudioFormat.CHANNEL_IN_MONO,
            AudioFormat.ENCODING_PCM_16BIT, mAudioRecordBufferSize);

    mNotifyChannelList = new ArrayList<String>();

    setupLayout();

    if (savedInstanceState != null) {
        mCurrentSelectedPosition = savedInstanceState.getInt(STATE_SELECTED_POSITION);
    }

    //      mRegistrationBroadcastReceiver = new BroadcastReceiver() {
    //         @Override
    //         public void onReceive(Context context, Intent intent) {
    //
    //            // checking for type intent filter
    //            if (intent.getAction().equals(MainApplication.REGISTRATION_COMPLETE)) {
    //               // gcm successfully registered
    //               // now subscribe to `global` topic to receive app wide notifications
    //               String token = intent.getStringExtra("token");
    //
    //               //Toast.makeText(getApplicationContext(), "GCM registration token: " + token, Toast.LENGTH_LONG).show();
    //
    //            } else if (intent.getAction().equals(MainApplication.SENT_TOKEN_TO_SERVER)) {
    //               // gcm registration id is stored in our server's MySQL
    //
    //               Toast.makeText(getApplicationContext(), "GCM registration token is stored in server!", Toast.LENGTH_LONG).show();
    //
    //            } else if (intent.getAction().equals(MainApplication.PUSH_NOTIFICATION)) {
    //               // new push notification is received
    //
    //               Toast.makeText(getApplicationContext(), "Push notification is received!", Toast.LENGTH_LONG).show();
    //            }
    //         }
    //      };
    //
    if (checkPlayServices()) {
        registerGCM();
    }

}

From source file:activities.Activity_Main.java

/** Called when the activity is first created. */
@Override//from  w  ww  . java  2  s . co  m
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    myself = this;
    setContentView(R.layout.activity_home);

    SP_params = PreferenceManager.getDefaultSharedPreferences(this);
    SP_prefEditor = SP_params.edit();
    Tracer = tracerengine.getInstance(SP_params);

    //Added by Doume
    File storage = new File(Environment.getExternalStorageDirectory() + "/domodroid/.conf/");
    if (!storage.exists())
        storage.mkdirs();
    //Configure Tracer tool initial state
    File logpath = new File(Environment.getExternalStorageDirectory() + "/domodroid/.log/");
    if (!logpath.exists())
        logpath.mkdirs();

    String currlogpath = SP_params.getString("LOGNAME", "");
    if (currlogpath.equals("")) {
        //Not yet existing prefs : Configure debugging by default, to configure Tracer
        currlogpath = Environment.getExternalStorageDirectory() + "/domodroid/.log/";
        SP_prefEditor.putString("LOGPATH", currlogpath);
        SP_prefEditor.putString("LOGNAME", "Domodroid.txt");
        SP_prefEditor.putBoolean("SYSTEMLOG", false);
        SP_prefEditor.putBoolean("TEXTLOG", false);
        SP_prefEditor.putBoolean("SCREENLOG", false);
        SP_prefEditor.putBoolean("LOGCHANGED", true);
        SP_prefEditor.putBoolean("LOGAPPEND", false);
    } else {
        SP_prefEditor.putBoolean("LOGCHANGED", true); //To force Tracer to consider current settings
    }
    //prefEditor.putBoolean("SYSTEMLOG", false);      // For tests : no system logs....
    SP_prefEditor.putBoolean("SYSTEMLOG", true); // For tests : with system logs....

    SP_prefEditor.commit();

    Tracer.set_profile(SP_params);
    // Create .nomedia file, that will prevent Android image gallery from showing domodroid file
    String nomedia = Environment.getExternalStorageDirectory() + "/domodroid/.nomedia";
    try {
        if (!(new File(nomedia).exists())) {
            new FileOutputStream(nomedia).close();
        }
    } catch (Exception e) {
    }

    appname = (ImageView) findViewById(R.id.app_name);

    LoadSelections();

    // Prepare a listener to know when a sync dialog is closed...
    if (sync_listener == null) {
        sync_listener = new DialogInterface.OnDismissListener() {

            public void onDismiss(DialogInterface dialog) {

                Tracer.d(mytag, "sync dialog has been closed !");

                // Is it success or fail ?
                if (((Dialog_Synchronize) dialog).need_refresh) {
                    // Sync has been successful : Force to refresh current main view
                    Tracer.d(mytag, "sync dialog requires a refresh !");
                    reload = true; // Sync being done, consider shared prefs are OK
                    VG_parent.removeAllViews();
                    if (WU_widgetUpdate != null) {
                        WU_widgetUpdate.resync();
                    } else {
                        Tracer.i(mytag + ".onCreate", "WidgetUpdate is null startCacheengine!");
                        startCacheEngine();
                    }
                    Bundle b = new Bundle();
                    //Notify sync complete to parent Dialog
                    b.putInt("id", 0);
                    b.putString("type", "root");
                    Message msg = new Message();
                    msg.setData(b);
                    if (widgetHandler != null)
                        widgetHandler.sendMessage(msg); // That should force to refresh Views
                    /* */
                    if (WU_widgetUpdate != null) {
                        WU_widgetUpdate.Disconnect(0); //That should disconnect all opened widgets from cache engine
                        //widgetUpdate.dump_cache();   //For debug
                        dont_kill = true; // to avoid engines kill when onDestroy()
                    }
                    onResume();
                } else {
                    Tracer.d(mytag, "sync dialog end with no refresh !");

                }
                ((Dialog_Synchronize) dialog).need_refresh = false;
            }
        };
    }

    //update thread
    sbanim = new Handler() {
        @Override
        public void handleMessage(Message msg) {
            if (msg.what == 0) {
                appname.setImageDrawable(getResources().getDrawable(R.drawable.app_name2));
            } else if (msg.what == 1) {
                appname.setImageDrawable(getResources().getDrawable(R.drawable.app_name3));
            } else if (msg.what == 2) {
                appname.setImageDrawable(getResources().getDrawable(R.drawable.app_name1));
            } else if (msg.what == 3) {
                appname.setImageDrawable(getResources().getDrawable(R.drawable.app_name4));
            } else if (msg.what == 8000) {
                Tracer.e(mytag, "Request to display message : 8000");
                /*
                if(dialog_message == null) {
                   Create_message_box();
                }
                dialog_message.setMessage("Starting cache engine...");
                dialog_message.show();
                        
                */
            } else if (msg.what == 8999) {
                //Cache engine is ready for use....
                if (Tracer != null)
                    Tracer.e(mytag, "Cache engine has notified it's ready !");
                cache_ready = true;
                if (end_of_init_requested)
                    end_of_init();
                PG_dialog_message.dismiss();
            }
        }
    };

    //power management
    final PowerManager pm = (PowerManager) getSystemService(Context.POWER_SERVICE);
    this.PM_WakeLock = pm.newWakeLock(PowerManager.SCREEN_DIM_WAKE_LOCK, "");
    this.PM_WakeLock.acquire();

    //titlebar
    final FrameLayout titlebar = (FrameLayout) findViewById(R.id.TitleBar);
    titlebar.setBackgroundDrawable(Gradients_Manager.LoadDrawable("title", 40));

    //Parent view
    VG_parent = (ViewGroup) findViewById(R.id.home_container);

    LL_house_map = new LinearLayout(this);
    LL_house_map
            .setLayoutParams(new LinearLayout.LayoutParams(LayoutParams.FILL_PARENT, LayoutParams.FILL_PARENT));
    LL_house_map.setOrientation(LinearLayout.HORIZONTAL);
    LL_house_map.setPadding(5, 5, 5, 5);

    house = new Basic_Graphical_zone(getApplicationContext(), 0, Graphics_Manager.Names_Agent(this, "House"),
            "", "house", 0, "", null);
    house.setPadding(0, 0, 5, 0);
    map = new Basic_Graphical_zone(getApplicationContext(), 0, Graphics_Manager.Names_Agent(this, "Map"), "",
            "map", 0, "", null);
    map.setPadding(5, 0, 0, 0);

    LinearLayout.LayoutParams param = new LinearLayout.LayoutParams(LayoutParams.FILL_PARENT,
            LayoutParams.FILL_PARENT, 1.0f);

    house.setLayoutParams(param);
    house.setOnClickListener(new OnClickListener() {
        public void onClick(View v) {
            if (SP_params.getBoolean("SYNC", false)) {
                loadWigets(0, "root");
                historyPosition++;
                history.add(historyPosition, new String[] { "0", "root" });
            } else {
                if (AD_notSyncAlert == null)
                    createAlert();
                AD_notSyncAlert.show();
            }
        }
    });

    map.setLayoutParams(param);
    map.setOnClickListener(new OnClickListener() {
        public void onClick(View v) {
            if (SP_params.getBoolean("SYNC", false)) {
                //dont_freeze=true;      //To avoid WidgetUpdate engine freeze
                Tracer.w(mytag, "Before call to Map, Disconnect widgets from engine !");
                if (WU_widgetUpdate != null) {
                    WU_widgetUpdate.Disconnect(0); //That should disconnect all opened widgets from cache engine
                    //widgetUpdate.dump_cache();   //For debug
                    dont_kill = true; // to avoid engines kill when onDestroy()
                }
                INTENT_map = new Intent(Activity_Main.this, Activity_Map.class);
                Tracer.d(mytag, "Call to Map, run it now !");
                Tracer.Map_as_main = false;
                startActivity(INTENT_map);
            } else {
                if (AD_notSyncAlert == null)
                    createAlert();
                AD_notSyncAlert.show();
            }
        }
    });

    LL_house_map.addView(house);
    LL_house_map.addView(map);

    init_done = false;
    // Detect if it's the 1st use after installation...
    if (!SP_params.getBoolean("SPLASH", false)) {
        // Yes, 1st use !
        init_done = false;
        reload = false;
        if (backupprefs.exists()) {
            // A backup exists : Ask if reload it
            Tracer.v(mytag, "settings backup found after a fresh install...");

            DialogInterface.OnClickListener reload_listener = new DialogInterface.OnClickListener() {

                public void onClick(DialogInterface dialog, int which) {
                    Tracer.e(mytag, "Reload dialog returns : " + which);
                    if (which == dialog.BUTTON_POSITIVE) {
                        reload = true;
                    } else if (which == dialog.BUTTON_NEGATIVE) {
                        reload = false;
                    }
                    check_answer();
                    dialog.dismiss();
                }
            };
            dialog_reload = new AlertDialog.Builder(this);
            dialog_reload.setMessage(getText(R.string.home_reload));
            dialog_reload.setTitle(getText(R.string.reload_title));
            dialog_reload.setPositiveButton(getText(R.string.reloadOK), reload_listener);
            dialog_reload.setNegativeButton(getText(R.string.reloadNO), reload_listener);
            dialog_reload.show();
            init_done = false; //A choice is pending : Rest of init has to be completed...
        } else {
            //No settings backup found
            Tracer.v(mytag, "no settings backup found after fresh install...");
            end_of_init_requested = true;
            // open server config view
            Intent helpI = new Intent(Activity_Main.this, Preference.class);
            startActivity(helpI);
        }
    } else {
        // It's not the 1st use after fresh install
        // This method will be followed by 'onResume()'
        end_of_init_requested = true;
    }
    if (SP_params.getBoolean("SYNC", false)) {
        //A config exists and a sync as been done by past.
        if (WU_widgetUpdate == null) {
            Tracer.i(mytag + ".onCreate", "Params splach is false and WidgetUpdate is null startCacheengine!");
            startCacheEngine();
        }

    }

    Tracer.e(mytag, "OnCreate() complete !");
    // End of onCreate (UIThread)
}