Example usage for android.content Intent ACTION_MAIN

List of usage examples for android.content Intent ACTION_MAIN

Introduction

In this page you can find the example usage for android.content Intent ACTION_MAIN.

Prototype

String ACTION_MAIN

To view the source code for android.content Intent ACTION_MAIN.

Click Source Link

Document

Activity Action: Start as a main entry point, does not expect to receive data.

Usage

From source file:com.jungle.base.utils.MiscUtils.java

public static String getMainLauncherActivity() {
    try {/*from  w  ww  . j a va2 s  .  co m*/
        Context context = BaseApplication.getAppContext();
        PackageManager manager = context.getPackageManager();
        Intent intent = new Intent(Intent.ACTION_MAIN, null);
        intent.addCategory(Intent.CATEGORY_LAUNCHER);
        List<ResolveInfo> list = manager.queryIntentActivities(intent, 0);
        Collections.sort(list, new ResolveInfo.DisplayNameComparator(manager));

        String packageName = MiscUtils.getPackageName();
        for (ResolveInfo info : list) {
            if (TextUtils.equals(packageName, info.activityInfo.packageName)) {
                return info.activityInfo.name;
            }
        }
    } catch (Throwable e) {
        e.printStackTrace();
    }

    return null;
}

From source file:com.amrutpatil.makeanote.NotesActivity.java

@Override
public void onBackPressed() {

    Intent intent = new Intent(Intent.ACTION_MAIN);
    intent.addCategory(Intent.CATEGORY_HOME);
    intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
    startActivity(intent);/* w  w  w.j a  va 2 s  . co m*/
}

From source file:org.kaoriha.phonegap.plugins.releasenotification.Notifier.java

private void pollBackground() {
    if (getToken() == null) {
        rescheduleAfterFail();/*from   w  w w  . j  a va2  s  . c  om*/
        return;
    }

    ToNextReleasePolling tp = new ToNextReleasePolling();
    tp.poll();
    if (tp.isFailed) {
        Log.d(TAG, "ToNextReleasePolling failed");
        rescheduleAfterFail();
        return;
    }

    CataloguePolling cp = new CataloguePolling();
    cp.poll();
    if (cp.isFailed) {
        Log.d(TAG, "CataloguePolling failed");
        rescheduleAfterFail();
        return;
    }
    if (!cp.isNew) {
        if (tp.toNextRelease == -1) {
            schedule(RESCHEDULE_NEXT_UNKNOWN_SPAN);
        } else {
            schedule(tp.toNextRelease);
        }
        Log.d(TAG, "CataloguePolling not new");
        return;
    }

    String pushMessage;
    if (cp.catalogue.has(CATALOGUE_PUSH_MESSAGE_KEY)) {
        try {
            pushMessage = cp.catalogue.getString(CATALOGUE_PUSH_MESSAGE_KEY);
        } catch (JSONException e) {
            Log.i(TAG, "pollBackground()", e);
            pushMessage = pref.getString(SPKEY_DEFAULT_PUSH_MESSAGE, null);
        }
    } else {
        pushMessage = pref.getString(SPKEY_DEFAULT_PUSH_MESSAGE, null);
    }

    String lastSid;
    try {
        lastSid = getLastSid(cp.catalogue);
        if (lastSid.equals(pref.getString(SPKEY_LAST_SID, null))) {
            schedule(tp.toNextRelease);
        }
    } catch (JSONException e) {
        Log.d(TAG, "bad JSON", e);
        rescheduleAfterFail();
        return;
    }

    int icon = R.drawable.notification;
    Notification n = new Notification(icon, pushMessage, System.currentTimeMillis());
    n.flags = Notification.FLAG_AUTO_CANCEL;
    Intent i = new Intent(ctx, FlowerflowerActivity.class);
    i.setAction(Intent.ACTION_MAIN);
    i.setFlags(Intent.FLAG_ACTIVITY_SINGLE_TOP);
    PendingIntent pi = PendingIntent.getActivity(ctx, 0, i, 0);
    n.setLatestEventInfo(ctx.getApplicationContext(), pref.getString(SPKEY_TITLE, null), pushMessage, pi);
    NotificationManager nm = (NotificationManager) ctx.getSystemService(Context.NOTIFICATION_SERVICE);
    nm.notify(NOTIFICATION_ID, n);

    pref.edit().putString(SPKEY_LAST_SID, lastSid).putString(SPKEY_LAST_CATALOGUE_ETAG, cp.etag).commit();

    clearFailRepeat();

    schedule(tp.toNextRelease);

    Log.d(TAG, "pollBackground() success");
}

From source file:com.android.purenexussettings.TinkerActivity.java

public void launchcLock() {
    Intent link = new Intent(Intent.ACTION_MAIN);
    ComponentName cn = new ComponentName(KEY_LOCK_CLOCK_PACKAGE_NAME, KEY_LOCK_CLOCK_CLASS_NAME);
    link.setComponent(cn);//from w  ww  .j  a  v a  2s .c o  m
    startActivity(link);
}

From source file:com.pdmanager.views.patient.MainActivity.java

@Override
public void onMessageReceived(final CNMessage cnMessage) {
    if (application.getUniqueId().equals(cnMessage.getUniqueId())) {
        return;/*from w  ww .ja va  2  s.  c o m*/
    }

    if (cnMessage.getMessageType() == CNMessage.CNMessageType.Calling) {

        if (application.isInConference()) {
            application.sendCNMessage(cnMessage.getFrom(), CNMessage.CNMessageType.Busy, null);
            return;
        }

        callDialog = new AlertDialog.Builder(this).create();
        LayoutInflater inflater = getLayoutInflater();
        View incomingCallDialog = inflater.inflate(R.layout.incoming_call_dialog, null);
        incomingCallDialog.setAlpha(0.5f);
        callDialog.setView(incomingCallDialog);

        TextView caller = (TextView) incomingCallDialog.findViewById(R.id.caller);
        caller.setText(cnMessage.getDisplayName());

        Button answerButton = (Button) incomingCallDialog.findViewById(R.id.answer_button);
        answerButton.setOnClickListener(new View.OnClickListener() {

            @Override
            public void onClick(View v) {
                application.setConferenceId(cnMessage.getConferenceId());
                application.sendCNMessage(cnMessage.getFrom(), CNMessage.CNMessageType.AnswerAccept, null);
                callDialog.hide();
                currentRingtone.stop();

                Intent intent = new Intent(application.getContext(), MainActivity.class);
                intent.setAction(Intent.ACTION_MAIN);
                intent.addCategory(Intent.CATEGORY_LAUNCHER);
                startActivity(intent);

                application.join(application.getConferenceId(), true);
            }
        });

        Button declineButton = (Button) incomingCallDialog.findViewById(R.id.decline_button);
        declineButton.setOnClickListener(new View.OnClickListener() {

            @Override
            public void onClick(View v) {
                application.sendCNMessage(cnMessage.getFrom(), CNMessage.CNMessageType.AnswerDecline, null);
                currentRingtone.stop();
                callDialog.hide();
            }
        });

        callDialog.setCancelable(false);
        callDialog.getWindow().setType(WindowManager.LayoutParams.TYPE_SYSTEM_ALERT);
        //play current Ringtone
        currentRingtone.play();
        callDialog.show();
    } else if (cnMessage.getMessageType() == CNMessage.CNMessageType.Cancel) {
        currentRingtone.stop();
        callDialog.hide();
    } else if (cnMessage.getMessageType() == CNMessage.CNMessageType.EndCall) {
        if (application.leave()) {
            int count = getFragmentManager().getBackStackEntryCount();
            String name = getFragmentManager().getBackStackEntryAt(count - 2).getName();
            getFragmentManager().popBackStack(name, FragmentManager.POP_BACK_STACK_INCLUSIVE);
        }
    }
}

From source file:de.blinkt.openvpn.fragments.LogFragment.java

@Override
public void onActivityResult(int requestCode, int resultCode, Intent data) {
    if (requestCode == START_VPN_CONFIG && resultCode == Activity.RESULT_OK) {
        String configuredVPN = data.getStringExtra(VpnProfile.EXTRA_PROFILEUUID);

        final VpnProfile profile = ProfileManager.get(getActivity(), configuredVPN);
        ProfileManager.getInstance(getActivity()).saveProfile(getActivity(), profile);
        // Name could be modified, reset List adapter

        AlertDialog.Builder dialog = new AlertDialog.Builder(getActivity());
        dialog.setTitle(R.string.configuration_changed);
        dialog.setMessage(R.string.restart_vpn_after_change);

        dialog.setPositiveButton(R.string.restart, new DialogInterface.OnClickListener() {
            @Override/*from w  w  w . j a v a  2s  .  c o  m*/
            public void onClick(DialogInterface dialog, int which) {
                Intent intent = new Intent(getActivity(), LaunchVPN.class);
                intent.putExtra(LaunchVPN.EXTRA_KEY, profile.getUUIDString());
                intent.setAction(Intent.ACTION_MAIN);
                startActivity(intent);
            }

        });
        dialog.setNegativeButton(R.string.ignore, null);
        dialog.create().show();
    }
    super.onActivityResult(requestCode, resultCode, data);
}

From source file:com.battlelancer.seriesguide.ui.ShowFragment.java

private void createShortcut() {
    if (!Utils.hasAccessToX(getActivity())) {
        Utils.advertiseSubscription(getActivity());
        return;//from  www . ja  v  a2 s  . c o m
    }

    if (mShowCursor == null) {
        return;
    }

    // create the shortcut
    ShortcutUtils.createShortcut(getActivity(), mShowTitle, mShowPoster, getShowTvdbId());

    // drop to home screen
    startActivity(new Intent(Intent.ACTION_MAIN).addCategory(Intent.CATEGORY_HOME)
            .setFlags(Intent.FLAG_ACTIVITY_NEW_TASK));

    // Analytics
    fireTrackerEvent("Add to Homescreen");
}

From source file:at.jclehner.rxdroid.NotificationReceiver.java

static void rescheduleAlarmsAndUpdateNotification(Context context, boolean silent) {
    if (context == null)
        context = RxDroid.getContext();/* w  w  w  . j  a  v a  2  s.com*/
    final Intent intent = new Intent(context, NotificationReceiver.class);
    intent.setAction(Intent.ACTION_MAIN);
    intent.putExtra(NotificationReceiver.EXTRA_SILENT, silent);
    context.sendBroadcast(intent);
}

From source file:de.gebatzens.sia.MainActivity.java

@Override
protected void onCreate(Bundle savedInstanceState) {
    setTheme(SIAApp.SIA_APP.school.getTheme());
    super.onCreate(savedInstanceState);
    Log.w("ggvp", "CREATE NEW MAINACTIVITY");
    //Debug.startMethodTracing("sia3");
    SIAApp.SIA_APP.activity = this;
    savedState = savedInstanceState;/*ww  w  .  ja v  a  2 s .  c om*/

    final FragmentData.FragmentList fragments = SIAApp.SIA_APP.school.fragments;

    Intent intent = getIntent();
    if (intent != null && intent.getStringExtra("fragment") != null) {
        FragmentData frag = fragments
                .getByType(FragmentData.FragmentType.valueOf(intent.getStringExtra("fragment"))).get(0);
        SIAApp.SIA_APP.setFragmentIndex(fragments.indexOf(frag));
    }

    if (intent != null && intent.getBooleanExtra("reload", false)) {
        SIAApp.SIA_APP.refreshAsync(null, true, fragments.get(SIAApp.SIA_APP.getFragmentIndex()));
        intent.removeExtra("reload");
    }

    setContentView(R.layout.activity_main);

    FragmentTransaction transaction = getSupportFragmentManager().beginTransaction();
    mContent = getFragment();
    transaction.replace(R.id.content_fragment, mContent, "gg_content_fragment");
    transaction.commit();

    Log.d("ggvp", "DATA: " + fragments.get(SIAApp.SIA_APP.getFragmentIndex()).getData());
    if (fragments.get(SIAApp.SIA_APP.getFragmentIndex()).getData() == null)
        SIAApp.SIA_APP.refreshAsync(null, true, fragments.get(SIAApp.SIA_APP.getFragmentIndex()));

    if ("Summer".equals(SIAApp.SIA_APP.getCurrentThemeName())) {
        ImageView summerNavigationPalm = (ImageView) findViewById(R.id.summer_navigation_palm);
        summerNavigationPalm.setImageResource(R.drawable.summer_palm);
        ImageView summerBackgroundImage = (ImageView) findViewById(R.id.summer_background_image);
        summerBackgroundImage.setImageResource(R.drawable.summer_background);
    }

    mToolBar = (Toolbar) findViewById(R.id.toolbar);
    mToolBar.setOnMenuItemClickListener(new Toolbar.OnMenuItemClickListener() {
        @Override
        public boolean onMenuItemClick(MenuItem menuItem) {

            switch (menuItem.getItemId()) {
            case R.id.action_refresh:
                ((SwipeRefreshLayout) mContent.getView().findViewById(R.id.refresh)).setRefreshing(true);
                SIAApp.SIA_APP.refreshAsync(new Runnable() {
                    @Override
                    public void run() {
                        ((SwipeRefreshLayout) mContent.getView().findViewById(R.id.refresh))
                                .setRefreshing(false);
                    }
                }, true, fragments.get(SIAApp.SIA_APP.getFragmentIndex()));
                return true;
            case R.id.action_settings:
                Intent i = new Intent(MainActivity.this, SettingsActivity.class);
                startActivityForResult(i, 1);
                return true;
            case R.id.action_addToCalendar:
                showExamDialog();
                return true;
            case R.id.action_help:
                AlertDialog.Builder builder = new AlertDialog.Builder(MainActivity.this);
                builder.setTitle(getApplication().getString(R.string.help));
                builder.setMessage(getApplication().getString(R.string.exam_explain));
                builder.setPositiveButton(getApplication().getString(R.string.close),
                        new DialogInterface.OnClickListener() {
                            @Override
                            public void onClick(DialogInterface dialog, int which) {
                                dialog.dismiss();
                            }
                        });
                builder.create().show();
                return true;
            }

            return false;
        }
    });

    updateToolbar(SIAApp.SIA_APP.school.name, fragments.get(SIAApp.SIA_APP.getFragmentIndex()).name);

    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
        SIAApp.SIA_APP.setStatusBarColorTransparent(getWindow()); // because of the navigation drawer
    }

    mDrawerLayout = (DrawerLayout) findViewById(R.id.drawer_layout);
    mDrawerToggle = new ActionBarDrawerToggle(this, mDrawerLayout, mToolBar, R.string.drawer_open,
            R.string.drawer_close) {

        /** Called when a drawer has settled in a completely closed state. */
        public void onDrawerClosed(View view) {
            super.onDrawerClosed(view);
            invalidateOptionsMenu(); // creates call to onPrepareOptionsMenu()
        }

        /** Called when a drawer has settled in a completely open state. */
        public void onDrawerOpened(View drawerView) {
            super.onDrawerOpened(drawerView);
            invalidateOptionsMenu(); // creates call to onPrepareOptionsMenu()
        }
    };
    mDrawerLayout.addDrawerListener(mDrawerToggle);
    navigationView = (NavigationView) findViewById(R.id.navigation_view);
    mNavigationHeader = navigationView.getHeaderView(0);
    mNavigationSchoolpictureText = (TextView) mNavigationHeader.findViewById(R.id.drawer_image_text);
    mNavigationSchoolpictureText.setText(SIAApp.SIA_APP.school.name);
    mNavigationSchoolpicture = (ImageView) mNavigationHeader.findViewById(R.id.navigation_schoolpicture);
    mNavigationSchoolpicture.setImageBitmap(SIAApp.SIA_APP.school.loadImage());
    mNavigationSchoolpictureLink = mNavigationHeader.findViewById(R.id.navigation_schoolpicture_link);
    mNavigationSchoolpictureLink.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View viewIn) {
            mDrawerLayout.closeDrawers();
            Intent linkIntent = new Intent(Intent.ACTION_VIEW);
            linkIntent.setData(Uri.parse(SIAApp.SIA_APP.school.website));
            startActivity(linkIntent);
        }
    });

    final Menu menu = navigationView.getMenu();
    menu.clear();
    for (int i = 0; i < fragments.size(); i++) {
        MenuItem item = menu.add(R.id.fragments, Menu.NONE, i, fragments.get(i).name);
        item.setIcon(fragments.get(i).getIconRes());
    }

    menu.add(R.id.settings, R.id.settings_item, fragments.size(), R.string.settings);
    menu.setGroupCheckable(R.id.fragments, true, true);
    menu.setGroupCheckable(R.id.settings, false, false);

    final Menu navMenu = navigationView.getMenu();
    selectedItem = SIAApp.SIA_APP.getFragmentIndex();
    if (selectedItem != -1)
        navMenu.getItem(selectedItem).setChecked(true);

    navigationView.setNavigationItemSelectedListener(new NavigationView.OnNavigationItemSelectedListener() {
        @Override
        public boolean onNavigationItemSelected(MenuItem menuItem) {
            if (menuItem.getItemId() == R.id.settings_item) {
                mDrawerLayout.closeDrawers();
                Intent i = new Intent(MainActivity.this, SettingsActivity.class);
                startActivityForResult(i, 1);
            } else {
                final int index = menuItem.getOrder();
                if (SIAApp.SIA_APP.getFragmentIndex() != index) {
                    SIAApp.SIA_APP.setFragmentIndex(index);
                    menuItem.setChecked(true);
                    updateToolbar(SIAApp.SIA_APP.school.name, menuItem.getTitle().toString());
                    mContent = getFragment();
                    Animation fadeOut = AnimationUtils.loadAnimation(getApplicationContext(), R.anim.fade_out);
                    fadeOut.setAnimationListener(new Animation.AnimationListener() {

                        @Override
                        public void onAnimationStart(Animation animation) {

                        }

                        @Override
                        public void onAnimationEnd(Animation animation) {
                            FrameLayout contentFrame = (FrameLayout) findViewById(R.id.content_fragment);
                            contentFrame.setVisibility(View.INVISIBLE);
                            if (fragments.get(index).getData() == null)
                                SIAApp.SIA_APP.refreshAsync(null, true, fragments.get(index));

                            //removeAllFragments();

                            FragmentTransaction transaction = getSupportFragmentManager().beginTransaction();
                            transaction.replace(R.id.content_fragment, mContent, "gg_content_fragment");
                            transaction.commit();

                            snowView.updateSnow();
                        }

                        @Override
                        public void onAnimationRepeat(Animation animation) {

                        }
                    });
                    FrameLayout contentFrame = (FrameLayout) findViewById(R.id.content_fragment);
                    contentFrame.startAnimation(fadeOut);
                    mDrawerLayout.closeDrawers();
                } else {
                    mDrawerLayout.closeDrawers();
                }
            }
            return true;
        }
    });

    if (Build.VERSION.SDK_INT >= 25) {
        ShortcutManager shortcutManager = getSystemService(ShortcutManager.class);
        shortcutManager.removeAllDynamicShortcuts();

        for (int i = 0; i < fragments.size(); i++) {
            Drawable drawable = getDrawable(fragments.get(i).getIconRes());
            Bitmap icon;
            if (drawable instanceof VectorDrawable) {
                icon = Bitmap.createBitmap(drawable.getIntrinsicWidth(), drawable.getIntrinsicHeight(),
                        Bitmap.Config.ARGB_8888);
                Canvas canvas = new Canvas(icon);
                drawable.setBounds(0, 0, canvas.getWidth(), canvas.getHeight());
                drawable.draw(canvas);
            } else {
                icon = BitmapFactory.decodeResource(getResources(), fragments.get(i).getIconRes());
            }

            Bitmap connectedIcon = Bitmap.createBitmap(icon.getWidth(), icon.getHeight(),
                    Bitmap.Config.ARGB_8888);
            Canvas canvas = new Canvas(connectedIcon);
            Paint paint = new Paint();
            paint.setAntiAlias(true);
            paint.setColor(Color.parseColor("#f5f5f5"));
            canvas.drawCircle(icon.getWidth() / 2, icon.getHeight() / 2, icon.getWidth() / 2, paint);
            paint.setColorFilter(
                    new PorterDuffColorFilter(SIAApp.SIA_APP.school.getColor(), PorterDuff.Mode.SRC_ATOP));
            canvas.drawBitmap(icon, null, new RectF(icon.getHeight() / 4.0f, icon.getHeight() / 4.0f,
                    icon.getHeight() - icon.getHeight() / 4.0f, icon.getHeight() - icon.getHeight() / 4.0f),
                    paint);

            Intent newTaskIntent = new Intent(this, MainActivity.class);
            newTaskIntent.setAction(Intent.ACTION_MAIN);
            newTaskIntent.putExtra("fragment", fragments.get(i).type.toString());

            ShortcutInfo shortcut = new ShortcutInfo.Builder(this, fragments.get(i).name)
                    .setShortLabel(fragments.get(i).name).setLongLabel(fragments.get(i).name)
                    .setIcon(Icon.createWithBitmap(connectedIcon)).setIntent(newTaskIntent).build();

            shortcutManager.addDynamicShortcuts(Arrays.asList(shortcut));
        }
    }

    if (SIAApp.SIA_APP.preferences.getBoolean("app_130_upgrade", true)) {
        if (!SIAApp.SIA_APP.preferences.getBoolean("first_use_filter", true)) {
            TextDialog.newInstance(R.string.upgrade1_3title, R.string.upgrade1_3)
                    .show(getSupportFragmentManager(), "upgrade_dialog");
        }

        SIAApp.SIA_APP.preferences.edit().putBoolean("app_130_upgrade", false).apply();
    }

    snowView = (SnowView) findViewById(R.id.snow_view);

    shareToolbar = (Toolbar) findViewById(R.id.share_toolbar);
    shareToolbar.getMenu().clear();
    shareToolbar.inflateMenu(R.menu.share_toolbar_menu);
    shareToolbar.setNavigationOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View view) {
            toggleShareToolbar(false);
            for (Shareable s : MainActivity.this.shared) {
                s.setMarked(false);
            }
            MainActivity.this.shared.clear();

            mContent.updateFragment();
        }
    });

    shareToolbar.setOnMenuItemClickListener(new Toolbar.OnMenuItemClickListener() {
        @Override
        public boolean onMenuItemClick(MenuItem item) {
            toggleShareToolbar(false);

            HashMap<Date, ArrayList<Shareable>> dates = new HashMap<Date, ArrayList<Shareable>>();

            for (Shareable s : MainActivity.this.shared) {
                ArrayList<Shareable> list = dates.get(s.getDate());
                if (list == null) {
                    list = new ArrayList<Shareable>();
                    dates.put(s.getDate(), list);
                }

                list.add(s);

                s.setMarked(false);
            }
            MainActivity.this.shared.clear();

            List<Date> dateList = new ArrayList<Date>(dates.keySet());
            Collections.sort(dateList);
            String content = "";

            for (Date key : dateList) {
                content += SubstListAdapter.translateDay(key) + "\n\n";

                Collections.sort(dates.get(key));
                for (Shareable s : dates.get(key)) {
                    content += s.getShareContent() + "\n";
                }

                content += "\n";
            }

            content = content.substring(0, content.length() - 1);

            mContent.updateFragment();

            if (item.getItemId() == R.id.action_copy) {
                ClipboardManager clipboard = (ClipboardManager) getSystemService(Context.CLIPBOARD_SERVICE);

                ClipData clip = ClipData.newPlainText(getString(R.string.entries), content);
                clipboard.setPrimaryClip(clip);
            } else if (item.getItemId() == R.id.action_share) {
                Intent sendIntent = new Intent();
                sendIntent.setAction(Intent.ACTION_SEND);
                sendIntent.putExtra(Intent.EXTRA_TEXT, content);
                sendIntent.setType("text/plain");
                startActivity(Intent.createChooser(sendIntent, getResources().getText(R.string.send_to)));
            }

            return true;
        }
    });

    if (shared.size() > 0) {
        shareToolbar.setVisibility(View.VISIBLE);
        updateShareToolbarText();
    }

    // if a fragment is opened via a notification or a shortcut reset the shared entries
    // delete extra fragment because the same intent is used when the device gets rotated and the user could have opened a new fragment
    if (intent != null && intent.hasExtra("fragment")) {
        resetShareToolbar();
        intent.removeExtra("fragment");
    }

}

From source file:org.smilec.smile.ui.GeneralActivity.java

@SuppressWarnings("deprecation")
@Override/* w ww  .jav  a  2s .c om*/
public boolean onOptionsItemSelected(MenuItem item) {
    switch (item.getItemId()) {
    case R.id.bt_restart:
        AlertDialog.Builder builderRestart = new AlertDialog.Builder(this);
        builderRestart.setMessage(R.string.restart_game).setCancelable(false)
                .setPositiveButton("Yes", new DialogInterface.OnClickListener() {

                    @Override
                    public void onClick(DialogInterface dialog, int id) {

                        try {
                            //new SmilePlugServerManager().connect(ip, GeneralActivity.this);
                            new SmilePlugServerManager().resetGame(ip, GeneralActivity.this);
                            // QuestionsManager.resetListOfDeletedQuestions(GeneralActivity.this);
                            GeneralActivity.this.finish();
                        } catch (NetworkErrorException e) {
                            ActivityUtil.showLongToast(GeneralActivity.this,
                                    R.string.toast_down_or_unavailable);
                            Log.e(Constants.LOG_CATEGORY, "Error: ", e);
                        }
                    }

                }).setNegativeButton("No", new DialogInterface.OnClickListener() {
                    @Override
                    public void onClick(DialogInterface dialog, int id) {
                        dialog.cancel();
                    }
                });
        AlertDialog alertRestart = builderRestart.create();
        alertRestart.show();
        break;
    case R.id.bt_retake:
        AlertDialog.Builder builderRetake = new AlertDialog.Builder(this);
        builderRetake.setMessage(R.string.retake_game).setCancelable(false)
                .setPositiveButton("Yes", new DialogInterface.OnClickListener() {
                    @Override
                    public void onClick(DialogInterface dialog, int id) {
                        try {
                            new SmilePlugServerManager().startRetakeQuestions(ip, GeneralActivity.this, board);
                            ActivityUtil.showLongToast(GeneralActivity.this, R.string.toast_retaking);

                            Intent intent = new Intent(GeneralActivity.this,
                                    org.smilec.smile.ui.UsePreparedQuestionsActivity.class);
                            intent.putExtra(GeneralActivity.PARAM_IP, ip);
                            status = CurrentMessageStatus.RE_TAKE.name();
                            intent.putExtra(GeneralActivity.PARAM_STATUS, status);
                            startActivity(intent);

                        } catch (NetworkErrorException e) {
                            Log.e(Constants.LOG_CATEGORY, "Error: ", e);
                        }
                    }
                }).setNegativeButton("No", new DialogInterface.OnClickListener() {
                    @Override
                    public void onClick(DialogInterface dialog, int id) {
                        dialog.cancel();
                    }
                });
        AlertDialog alertRetake = builderRetake.create();
        alertRetake.show();
        break;
    case R.id.bt_about:
        Dialog aboutDialog = new Dialog(this, R.style.Dialog);
        aboutDialog.setContentView(R.layout.about);
        Display displaySize = ActivityUtil.getDisplaySize(getApplicationContext());
        aboutDialog.getWindow().setLayout(displaySize.getWidth(), displaySize.getHeight());
        aboutDialog.show();
        break;
    case R.id.bt_exit:
        AlertDialog.Builder builderExit = new AlertDialog.Builder(this);
        builderExit.setMessage(R.string.exit).setCancelable(false)
                .setPositiveButton("Yes", new DialogInterface.OnClickListener() {
                    @Override
                    public void onClick(DialogInterface dialog, int id) {
                        Intent intent = new Intent(Intent.ACTION_MAIN);
                        intent.addCategory(Intent.CATEGORY_HOME);
                        intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
                        startActivity(intent);

                        try {
                            new SmilePlugServerManager().resetGame(ip, GeneralActivity.this);
                        } catch (NetworkErrorException e) {
                            Log.e(Constants.LOG_CATEGORY, "Error: ", e);
                        }

                        // QuestionsManager.resetListOfDeletedQuestions(GeneralActivity.this);
                        GeneralActivity.this.finish();
                    }
                }).setNegativeButton("No", new DialogInterface.OnClickListener() {
                    @Override
                    public void onClick(DialogInterface dialog, int id) {
                        dialog.cancel();
                    }
                });
        AlertDialog alertExit = builderExit.create();
        alertExit.show();
        break;
    }
    return true;
}