Example usage for android.app Activity finish

List of usage examples for android.app Activity finish

Introduction

In this page you can find the example usage for android.app Activity finish.

Prototype

public void finish() 

Source Link

Document

Call this when your activity is done and should be closed.

Usage

From source file:com.example.flashcards.WizardActivity.java

public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_wizard);

    if (savedInstanceState != null) {
        mWizardModel.load(savedInstanceState.getBundle("model"));
    }//from   ww  w. java  2  s.co  m

    mWizardModel.registerListener(this);

    mPagerAdapter = new MyPagerAdapter(getSupportFragmentManager());
    mPager = (ViewPager) findViewById(R.id.pager);
    mPager.setAdapter(mPagerAdapter);
    mStepPagerStrip = (StepPagerStrip) findViewById(R.id.strip);
    mStepPagerStrip.setOnPageSelectedListener(new StepPagerStrip.OnPageSelectedListener() {
        @Override
        public void onPageStripSelected(int position) {
            position = Math.min(mPagerAdapter.getCount() - 1, position);
            if (mPager.getCurrentItem() != position) {
                mPager.setCurrentItem(position);
            }
        }
    });

    mNextButton = (Button) findViewById(R.id.next_button);
    mPrevButton = (Button) findViewById(R.id.prev_button);

    mPager.setOnPageChangeListener(new ViewPager.SimpleOnPageChangeListener() {
        @Override
        public void onPageSelected(int position) {
            mStepPagerStrip.setCurrentPage(position);

            if (mConsumePageSelectedEvent) {
                mConsumePageSelectedEvent = false;
                return;
            }

            mEditingAfterReview = false;
            updateBottomBar();
        }
    });
    final Activity activity = this;
    mNextButton.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View view) {
            if (mPager.getCurrentItem() == mCurrentPageSequence.size()) {
                callNewWord();
                try {
                    activity.finish();
                } catch (Throwable e) {
                    // TODO Auto-generated catch block
                    e.printStackTrace();
                }
            } else {
                if (mEditingAfterReview) {
                    mPager.setCurrentItem(mPagerAdapter.getCount() - 1);
                } else {
                    mPager.setCurrentItem(mPager.getCurrentItem() + 1);
                }
            }
        }
    });

    mPrevButton.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View view) {
            mPager.setCurrentItem(mPager.getCurrentItem() - 1);
        }
    });

    onPageTreeChanged();
    updateBottomBar();
}

From source file:org.flerda.android.honeypad.NoteListFragment.java

@Override
public void onAttach(Activity activity) {
    super.onAttach(activity);
    try {//from   ww w .  ja  va2  s.co  m
        // check that the containing activity implements our callback
        mContainerCallback = (NoteListEventsCallback) activity;
    } catch (ClassCastException e) {
        activity.finish();
        throw new ClassCastException(activity.toString() + " must implement NoteSelectedCallback");
    }
}

From source file:org.sufficientlysecure.keychain.ui.EditIdentitiesFragment.java

public void finishWithResult(OperationResult result) {
    Activity activity = getActivity();
    if (activity == null) {
        return;/*w  w w  . java2  s  . co m*/
    }

    Intent data = new Intent();
    data.putExtra(OperationResult.EXTRA_RESULT, result);
    activity.setResult(Activity.RESULT_OK, data);
    activity.finish();
}

From source file:com.breadwallet.BreadWalletApp.java

public void showDeviceNotSecuredWarning(final Activity context) {
    Log.e(TAG, "WARNING device is not secured!");
    new AlertDialog.Builder(context).setMessage(R.string.encryption_needed_for_wallet)
            .setNegativeButton(android.R.string.ok, new DialogInterface.OnClickListener() {
                public void onClick(DialogInterface dialog, int which) {
                    context.finish();
                }//  w  w  w .  ja  v a 2 s  . c o  m
            }).setIcon(android.R.drawable.ic_dialog_alert)
            .setOnDismissListener(new DialogInterface.OnDismissListener() {
                @Override
                public void onDismiss(DialogInterface dialog) {
                    context.finish();
                }
            }).show();
}

From source file:reportsas.com.formulapp.Formulario.java

public static void reiniciarActivity(Activity actividad, String parametro) {
    Intent intent = new Intent();

    intent.setClass(actividad, actividad.getClass());
    intent.putExtra("formulario", parametro);
    //llamamos a la actividad
    actividad.startActivity(intent);//from   ww w . j a  v a 2 s .c om
    //finalizamos la actividad actual
    actividad.finish();
}

From source file:me.acristoffers.tracker.fragments.PackageListFragment.java

@Override
public void onActivityCreated(final Bundle savedInstanceState) {
    super.onActivityCreated(savedInstanceState);

    final Activity activity = getActivity();
    final View view = getView();

    if (view == null || activity == null) {
        return;/*from  w  w w  .ja v  a  2  s  .  c om*/
    }

    PreferenceManager.setDefaultValues(activity, R.xml.preferences, false);

    AlarmReceiver.setAlarm(activity);

    recyclerView = (RecyclerView) view.findViewById(R.id.recyclerView);

    if (recyclerView == null) {
        activity.finish();
        System.exit(0);
    }

    final RecyclerView.LayoutManager layoutManager = new LinearLayoutManager(activity);
    recyclerView.setLayoutManager(layoutManager);

    final PackageListAdapter recyclerViewAdapter = new PackageListAdapter(activity,
            (PackageListActivity) activity);
    recyclerView.setAdapter(recyclerViewAdapter);

    swipeRefreshLayout = (SwipeRefreshLayout) view.findViewById(R.id.swipe_container);
    if (swipeRefreshLayout == null) {
        activity.finish();
        System.exit(0);
    }

    swipeRefreshLayout.setOnRefreshListener(new SwipeRefreshLayout.OnRefreshListener() {
        @Override
        public void onRefresh() {
            if (updating == 0) {
                checkForUpdates();
            }
        }
    });

    final Button button = (Button) view.findViewById(R.id.addButton);
    if (button != null) {
        button.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                final View view = View.inflate(activity, R.layout.search_package, null);

                final AlertDialog.Builder builder = new AlertDialog.Builder(activity);
                builder.setTitle(R.string.search_for_package);
                builder.setView(view);

                final EditText code = (EditText) view.findViewById(R.id.code);
                if (code != null) {
                    code.addTextChangedListener(new TrackCodeFormattingTextWatcher(code));
                }

                builder.setPositiveButton(R.string.ok, new DialogInterface.OnClickListener() {
                    @Override
                    public void onClick(DialogInterface dialogInterface, int i) {
                        final EditText code = (EditText) view.findViewById(R.id.code);
                        final EditText name = (EditText) view.findViewById(R.id.name);

                        Package p = null;

                        if (code != null) {
                            Editable editable = code.getText();
                            if (editable != null) {
                                String s = editable.toString();
                                p = new Package(s, getActivity(), null);
                            }
                        }

                        if (name != null && p != null) {
                            final Editable editable = name.getText();
                            if (editable != null) {
                                final String s = editable.toString();
                                p.setName(s);
                                p.setActive(true);
                                p.save();
                                checkForUpdates();
                            }
                        }

                        dialogInterface.dismiss();
                    }
                });

                builder.setNegativeButton(R.string.cancel, new DialogInterface.OnClickListener() {
                    @Override
                    public void onClick(DialogInterface dialogInterface, int i) {
                        dialogInterface.dismiss();
                    }
                });

                final AlertDialog dialog = builder.create();
                dialog.show();
            }
        });
    }
}

From source file:com.beem.project.beem.ui.wizard.AccountConfigureFragment.java

/**
 * Callback called when the user select an account from the device (Android Account api).
 *
 * @param accountName the account name/*from  ww  w  . j a  v  a2  s.com*/
 * @param accountType the account type
 *
 */
private void onDeviceAccountSelected(String accountName, String accountType) {
    Activity a = getActivity();
    saveCredentialAccount(accountName, accountType);
    // launch login
    Intent i = new Intent(a, Login.class);
    i.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
    startActivity(i);
    a.finish();
}

From source file:com.ichi2.anki.StudyOptionsFragment.java

private void closeStudyOptions(int result) {
    Activity a = getActivity();
    if (!mFragmented && a != null) {
        a.setResult(result);/*ww w. j av a2  s .c o  m*/
        a.finish();
        ActivityTransitionAnimation.slide(a, ActivityTransitionAnimation.RIGHT);
    } else if (a == null) {
        // getActivity() can return null if reference to fragment lingers after parent activity has been closed,
        // which is particularly relevant when using AsyncTasks.
        Timber.e("closeStudyOptions() failed due to getActivity() returning null");
    }
}

From source file:com.linkedin.android.eventsapp.ProfileActivity.java

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_profile);

    Bundle extras = getIntent() != null ? getIntent().getExtras() : new Bundle();
    final Person person = extras.getParcelable("person");
    final Activity currentActivity = this;
    final ActionBar bar = getActionBar();
    View viewActionBar = getLayoutInflater().inflate(R.layout.layout_action_bar, null);

    ImageView backView = (ImageView) viewActionBar.findViewById(R.id.actionbar_left);
    backView.setImageResource(R.drawable.arrow_left);
    backView.setVisibility(View.VISIBLE);
    backView.setClickable(true);/*from  ww  w.  j  a  v  a  2s.  c om*/
    backView.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            currentActivity.finish();
        }
    });

    ActionBar.LayoutParams params = new ActionBar.LayoutParams(ActionBar.LayoutParams.WRAP_CONTENT,
            ActionBar.LayoutParams.MATCH_PARENT);
    bar.setCustomView(viewActionBar, params);
    bar.setDisplayShowCustomEnabled(true);
    bar.setDisplayShowTitleEnabled(false);
    bar.setIcon(new ColorDrawable(Color.TRANSPARENT));
    bar.setBackgroundDrawable(new ColorDrawable(Color.parseColor("#F15153")));

    TextView attendeeNameView = (TextView) findViewById(R.id.attendeeName);
    attendeeNameView.setText(person.getFirstName() + " " + person.getLastName());

    final ImageView attendeeImageView = (ImageView) findViewById(R.id.attendeeImage);
    final TextView attendeeHeadlineView = (TextView) findViewById(R.id.attendeeHeadline);
    final TextView attendeeLocationView = (TextView) findViewById(R.id.attendeeLocation);

    boolean isAccessTokenValid = LISessionManager.getInstance(currentActivity).getSession().isValid();
    if (isAccessTokenValid) {
        String url = Constants.personByIdBaseUrl + person.getLinkedinId() + Constants.personProjection;
        APIHelper.getInstance(currentActivity).getRequest(currentActivity, url, new ApiListener() {
            @Override
            public void onApiSuccess(ApiResponse apiResponse) {
                try {
                    JSONObject s = apiResponse.getResponseDataAsJson();
                    String headline = s.has("headline") ? s.getString("headline") : "";
                    String pictureUrl = s.has("pictureUrl") ? s.getString("pictureUrl") : null;
                    JSONObject location = s.getJSONObject("location");
                    String locationName = location != null && location.has("name") ? location.getString("name")
                            : "";

                    attendeeHeadlineView.setText(headline);
                    attendeeLocationView.setText(locationName);
                    if (pictureUrl != null) {
                        new FetchImageTask(attendeeImageView).execute(pictureUrl);
                    } else {
                        attendeeImageView.setImageResource(R.drawable.ghost_person);
                    }
                } catch (JSONException e) {

                }

            }

            @Override
            public void onApiError(LIApiError apiError) {

            }
        });

        ViewStub viewOnLIStub = (ViewStub) findViewById(R.id.viewOnLIStub);
        View viewOnLI = viewOnLIStub.inflate();
        Button viewOnLIButton = (Button) viewOnLI.findViewById(R.id.viewOnLinkedInButton);
        viewOnLIButton.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                DeepLinkHelper.getInstance().openOtherProfile(currentActivity, person.getLinkedinId(),
                        new DeepLinkListener() {
                            @Override
                            public void onDeepLinkSuccess() {

                            }

                            @Override
                            public void onDeepLinkError(LIDeepLinkError error) {

                            }
                        });
            }
        });
    } else {
        attendeeImageView.setImageResource(R.drawable.ghost_person);
    }
}

From source file:org.sufficientlysecure.keychain.ui.linked.LinkedIdCreateGithubFragment.java

@Override
public void onStop() {
    super.onStop();

    if (mFinishOnStop) {
        Activity activity = getActivity();
        activity.setResult(Activity.RESULT_OK);
        activity.finish();
    }/*from ww w  .  ja  v a  2  s  . c o m*/
}