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.github.pockethub.ui.search.SearchRepositoryListFragment.java

/**
 * Check if the search query is an exact repository name/owner match and
 * open the repository activity and finish the current activity when it is
 *
 * @param query//from   w  ww  . j  ava2s.  com
 * @return true if query opened as repository, false otherwise
 */
private boolean openRepositoryMatch(final String query) {
    if (TextUtils.isEmpty(query))
        return false;

    Repo repoId = InfoUtils.createRepoFromUrl(query.trim());
    if (repoId == null)
        return false;

    Repo repo;
    repo = new GetRepoClient(getActivity(), InfoUtils.createRepoInfo(repoId)).executeSync();

    startActivity(RepositoryViewActivity.createIntent(repo));
    final Activity activity = getActivity();
    if (activity != null)
        activity.finish();
    return true;
}

From source file:net.d53.syman.mobile.ui.TrafficListFragment.java

@Override
public Loader<List<DatedViewSummary>> onCreateLoader(int id, Bundle args) {
    final List<DatedViewSummary> initialItems = items;
    return new ThrowableLoader<List<DatedViewSummary>>(getActivity(), items) {

        @Override/* www.  jav a  2 s .  c om*/
        public List<DatedViewSummary> loadData() throws Exception {
            final Gauge current = gauge;
            if (current != null)
                return current.getRecentDays();
            try {
                Gauge latest = serviceProvider.getService().getGauge(gaugeId);
                if (latest != null)
                    return latest.getRecentDays();
                else
                    return Collections.emptyList();
            } catch (OperationCanceledException e) {
                Activity activity = getActivity();
                if (activity != null)
                    activity.finish();
                return initialItems;
            }
        }
    };
}

From source file:com.openlocationcode.android.main.WelcomeActivity.java

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

    SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(this);
    // Second argument is the default to use if the preference can't be found
    int savedVersionCode = prefs.getInt(WELCOME_VERSION_CODE_SHOWN_PREF, 0);
    int appVersionCode = 0;
    try {//from   w w  w. j a  va 2  s  .  c om
        appVersionCode = getPackageManager().getPackageInfo(getPackageName(), 0).versionCode;
    } catch (NameNotFoundException nnfe) {
        Log.w(TAG, "Exception getting appVersionCode : " + nnfe);
    }

    final Intent intent = new Intent(this, MainActivity.class);
    final Activity activity = this;

    if (appVersionCode == savedVersionCode) {
        activity.startActivity(intent);
        activity.finish();
    } else {
        Log.i(TAG, "Starting welcome page");
        setContentView(R.layout.welcome);

        // Increase the margin on the image to account for the translucent status bar.
        ImageView welcomeImage = (ImageView) findViewById(R.id.welcome_image);
        LayoutParams layoutParams = (LayoutParams) welcomeImage.getLayoutParams();
        layoutParams.topMargin = layoutParams.topMargin + MainActivity.getStatusBarHeight(this);
        welcomeImage.setLayoutParams(layoutParams);

        Button button = (Button) findViewById(R.id.welcome_button);
        button.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                activity.startActivity(intent);
                activity.finish();
            }
        });

        SharedPreferences.Editor editor = prefs.edit();
        editor.putInt(WELCOME_VERSION_CODE_SHOWN_PREF, appVersionCode);
        editor.apply();
    }
}

From source file:nz.ac.auckland.lablet.ExperimentAnalysisFragment.java

protected void setupStandardMenu(Menu menu, MenuInflater inflater) {
    inflater.inflate(R.menu.standard_analysis_actions, menu);

    final MenuItem doneItem = menu.findItem(R.id.action_done);
    assert doneItem != null;
    doneItem.setOnMenuItemClickListener(new MenuItem.OnMenuItemClickListener() {
        @Override//from  w w w  .j  a va  2  s . c  om
        public boolean onMenuItemClick(MenuItem menuItem) {
            Activity activity = getActivity();
            activity.setResult(Activity.RESULT_OK);
            activity.finish();
            return true;
        }
    });

    // data menu item
    ExperimentAnalysisActivity experimentActivity = (ExperimentAnalysisActivity) getActivity();
    final ExperimentAnalysis experimentAnalysis = experimentActivity.getExperimentAnalysis();
    final MenuItem dataItem = menu.findItem(R.id.action_data);
    assert dataItem != null;
    dataItem.setOnMenuItemClickListener(new MenuItem.OnMenuItemClickListener() {
        @Override
        public boolean onMenuItemClick(MenuItem menuItem) {
            showDataMenu(experimentAnalysis);
            return true;
        }
    });
    // hide item if there is no more than one data
    if (experimentAnalysis.getAnalysisRunAt(analysisRef.runId).analysisList.size() == 1)
        dataItem.setVisible(false);
}

From source file:can.yrt.onebusaway.MyStopListFragmentBase.java

@Override
public void onListItemClick(ListView l, View v, int position, long id) {
    StopData stopData = getStopData(l, position);

    ArrivalsListActivity.Builder b = stopData.getArrivalsList();

    if (isShortcutMode()) {
        final Intent shortcut = UIHelp.makeShortcut(getActivity(), stopData.getUiName(), b.getIntent());

        Activity activity = getActivity();
        activity.setResult(Activity.RESULT_OK, shortcut);
        activity.finish();
    } else {/*from  w  w  w. j  a va 2 s . com*/
        b.setUpMode(NavHelp.UP_MODE_BACK);
        b.start();
    }
}

From source file:org.onebusaway.android.ui.MyStopListFragmentBase.java

@Override
public void onListItemClick(ListView l, View v, int position, long id) {
    StopData stopData = getStopData(l, position);

    ArrivalsListActivity.Builder b = stopData.getArrivalsList();

    if (isShortcutMode()) {
        final Intent shortcut = UIUtils.makeShortcut(getActivity(), stopData.getUiName(), b.getIntent());

        Activity activity = getActivity();
        activity.setResult(Activity.RESULT_OK, shortcut);
        activity.finish();
    } else {// www. ja  v a  2s. c o  m
        b.setUpMode(NavHelp.UP_MODE_BACK);
        b.start();
    }
}

From source file:net.naonedbus.fragment.impl.AddressSearchFragment.java

@Override
public void onListItemClick(final ListView l, final View v, final int position, final long id) {
    final AddressResult item = mAdapter.getItem(position);

    final Intent data = new Intent();
    data.putExtra("address", item.getAddress());
    data.putExtra("latitude", item.getLatitude());
    data.putExtra("longitude", item.getLongitude());
    data.putExtra("type", item.getType());
    data.putExtra("isCurrentLocation", item.isCurrentLocation());

    final Activity activity = getActivity();

    activity.setResult(1, data);/*  w w w . j  a  v a  2s.  c om*/
    activity.finish();
}

From source file:de.ub0r.android.smsdroid.ConversationListActivity.java

/**
 * Delete messages with a given {@link Uri}.
 * /*  ww w. jav  a  2s.c om*/
 * @param context
 *            {@link Context}
 * @param uri
 *            {@link Uri}
 * @param title
 *            title of Dialog
 * @param message
 *            message of the Dialog
 * @param activity
 *            {@link Activity} to finish when deleting.
 */
static void deleteMessages(final Context context, final Uri uri, final int title, final int message,
        final Activity activity) {
    Log.i(TAG, "deleteMessages(..," + uri + " ,..)");
    final Builder builder = new Builder(context);
    builder.setTitle(title);
    builder.setMessage(message);
    builder.setNegativeButton(android.R.string.no, null);
    builder.setPositiveButton(android.R.string.yes, new DialogInterface.OnClickListener() {
        @Override
        public void onClick(final DialogInterface dialog, final int which) {
            final int ret = context.getContentResolver().delete(uri, null, null);
            Log.d(TAG, "deleted: " + ret);
            if (activity != null && !activity.isFinishing()) {
                activity.finish();
            }
            if (ret > 0) {
                Conversation.flushCache();
                Message.flushCache();
                SmsReceiver.updateNewMessageNotification(context, null);
            }
        }
    });
    builder.show();
}

From source file:com.android.mail.ui.HelpFragment.java

@Override
public boolean onOptionsItemSelected(MenuItem item) {
    final int itemId = item.getItemId();
    if (itemId == android.R.id.home) {
        final Activity activity = getActivity();
        if (activity != null) {
            activity.finish();
        }/*from  www  .j  a v a  2s .  co m*/
        return true;
    } else if (itemId == R.id.view_app_url) {
        showAppUrl();
        return true;
    } else if (itemId == R.id.print_dialog) {
        print();
        return true;
    } else if (itemId == R.id.copyright_information) {
        showCopyrightInformation();
        return true;
    } else if (itemId == R.id.open_source_licenses) {
        showOpenSourceLicenses();
        return true;
    } else if (itemId == R.id.privacy_policy) {
        showPrivacyPolicy();
        return true;
    }
    return super.onOptionsItemSelected(item);
}

From source file:com.vst.functionframework.ui.SupportActivity.java

/**
 * skip to @param(cls)and call @param(aty's) finish() method
 *///  w w  w  . j a va 2 s  .  c  o  m
@Override
public void skipActivity(Activity aty, Intent it) {
    showActivity(aty, it);
    aty.finish();
}