Example usage for android.content Intent FLAG_ACTIVITY_CLEAR_TOP

List of usage examples for android.content Intent FLAG_ACTIVITY_CLEAR_TOP

Introduction

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

Prototype

int FLAG_ACTIVITY_CLEAR_TOP

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

Click Source Link

Document

If set, and the activity being launched is already running in the current task, then instead of launching a new instance of that activity, all of the other activities on top of it will be closed and this Intent will be delivered to the (now on top) old activity as a new Intent.

Usage

From source file:de.sitewaerts.cordova.documentviewer.DocumentViewerPlugin.java

private void _open(String url, String contentType, String packageId, String activity,
        CallbackContext callbackContext, Bundle viewerOptions) throws JSONException {
    clearTempFiles();/*from  w  ww  . ja va2  s .  c  om*/

    File file = getAccessibleFile(url);

    if (file != null && file.exists() && file.isFile()) {
        try {
            Intent intent = new Intent(Intent.ACTION_VIEW);
            Uri path = Uri.fromFile(file);

            // @see http://stackoverflow.com/questions/2780102/open-another-application-from-your-own-intent
            intent.addCategory(Intent.CATEGORY_EMBED);
            intent.setDataAndType(path, contentType);
            intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
            intent.putExtra(this.getClass().getName(), viewerOptions);
            //activity needs fully qualified name here
            intent.setComponent(new ComponentName(packageId, packageId + "." + activity));

            this.callbackContext = callbackContext;
            this.cordova.startActivityForResult(this, intent, REQUEST_CODE_OPEN);

            // send shown event
            JSONObject successObj = new JSONObject();
            successObj.put(Result.STATUS, PluginResult.Status.OK.ordinal());
            PluginResult result = new PluginResult(PluginResult.Status.OK, successObj);
            // need to keep callback for close event
            result.setKeepCallback(true);
            callbackContext.sendPluginResult(result);
        } catch (android.content.ActivityNotFoundException e) {
            JSONObject errorObj = new JSONObject();
            errorObj.put(Result.STATUS, PluginResult.Status.ERROR.ordinal());
            errorObj.put(Result.MESSAGE, "Activity not found: " + e.getMessage());
            callbackContext.error(errorObj);
        }
    } else {
        JSONObject errorObj = new JSONObject();
        errorObj.put(Result.STATUS, PluginResult.Status.ERROR.ordinal());
        errorObj.put(Result.MESSAGE, "File not found");
        callbackContext.error(errorObj);
    }
}

From source file:org.safegees.safegees.gui.view.MainActivity.java

public void setNoInternetAdvice(Context context) {
    final AlertDialog.Builder builder = new AlertDialog.Builder(context);
    builder.setMessage(getResources().getString(R.string.splash_advice_first_use_advice)).setCancelable(false)
            .setPositiveButton("OK", new DialogInterface.OnClickListener() {
                public void onClick(DialogInterface dialog, int id) {
                    Intent i = getBaseContext().getPackageManager()
                            .getLaunchIntentForPackage(getBaseContext().getPackageName());
                    i.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
                    startActivity(i);/*from w  w w . j a v a 2s  .c o m*/
                    //finish();
                }
            });
    AlertDialog alert = builder.create();
    alert.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 va  2 s . co  m*/
 * @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.ayogo.cordova.notification.ScheduledNotificationManager.java

public void showNotification(ScheduledNotification scheduledNotification) {
    LOG.v(NotificationPlugin.TAG, "showNotification: " + scheduledNotification.toString());

    NotificationManager nManager = (NotificationManager) context.getSystemService(Context.NOTIFICATION_SERVICE);

    NotificationCompat.Builder builder = new NotificationCompat.Builder(context);

    // Build the notification options
    builder.setDefaults(Notification.DEFAULT_ALL).setTicker(scheduledNotification.body)
            .setPriority(Notification.PRIORITY_HIGH).setAutoCancel(true);

    // TODO: add sound support
    // if (scheduledNotification.sound != null) {
    //     builder.setSound(sound);
    // }/*from w  ww .j  av  a2 s. c  om*/

    if (scheduledNotification.body != null) {
        builder.setContentTitle(scheduledNotification.title);
        builder.setContentText(scheduledNotification.body);
        builder.setStyle(new NotificationCompat.BigTextStyle().bigText(scheduledNotification.body));
    } else {
        //Default the title to the app name
        try {
            PackageManager pm = context.getPackageManager();
            ApplicationInfo applicationInfo = pm.getApplicationInfo(context.getPackageName(),
                    PackageManager.GET_META_DATA);

            String appName = applicationInfo.loadLabel(pm).toString();

            builder.setContentTitle(appName);
            builder.setContentText(scheduledNotification.title);
            builder.setStyle(new NotificationCompat.BigTextStyle().bigText(scheduledNotification.title));
        } catch (NameNotFoundException e) {
            LOG.v(NotificationPlugin.TAG, "Failed to set title for notification!");
            return;
        }
    }

    if (scheduledNotification.badge != null) {
        LOG.v(NotificationPlugin.TAG, "showNotification: has a badge!");
        builder.setSmallIcon(getResIdForDrawable(scheduledNotification.badge));
    } else {
        LOG.v(NotificationPlugin.TAG, "showNotification: has no badge, use app icon!");
        try {
            PackageManager pm = context.getPackageManager();
            ApplicationInfo applicationInfo = pm.getApplicationInfo(context.getPackageName(),
                    PackageManager.GET_META_DATA);
            Resources resources = pm.getResourcesForApplication(applicationInfo);
            builder.setSmallIcon(applicationInfo.icon);
        } catch (NameNotFoundException e) {
            LOG.v(NotificationPlugin.TAG, "Failed to set badge for notification!");
            return;
        }
    }

    if (scheduledNotification.icon != null) {
        LOG.v(NotificationPlugin.TAG, "showNotification: has an icon!");
        builder.setLargeIcon(getIconFromUri(scheduledNotification.icon));
    } else {
        LOG.v(NotificationPlugin.TAG, "showNotification: has no icon, use app icon!");
        try {
            PackageManager pm = context.getPackageManager();
            ApplicationInfo applicationInfo = pm.getApplicationInfo(context.getPackageName(),
                    PackageManager.GET_META_DATA);
            Resources resources = pm.getResourcesForApplication(applicationInfo);
            Bitmap appIconBitmap = BitmapFactory.decodeResource(resources, applicationInfo.icon);
            builder.setLargeIcon(appIconBitmap);
        } catch (NameNotFoundException e) {
            LOG.v(NotificationPlugin.TAG, "Failed to set icon for notification!");
            return;
        }
    }

    Intent launchIntent = context.getPackageManager().getLaunchIntentForPackage(context.getPackageName());
    launchIntent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP | Intent.FLAG_ACTIVITY_SINGLE_TOP);
    launchIntent.setAction("notification");

    PendingIntent contentIntent = PendingIntent.getActivity(context, 0, launchIntent,
            PendingIntent.FLAG_UPDATE_CURRENT);
    builder.setContentIntent(contentIntent);

    Notification notification = builder.build();

    NotificationManager notificationManager = (NotificationManager) context
            .getSystemService(Context.NOTIFICATION_SERVICE);
    LOG.v(NotificationPlugin.TAG, "notify!");
    notificationManager.notify(scheduledNotification.tag.hashCode(), notification);
}

From source file:com.artech.android.gcm.GcmIntentService.java

@SuppressLint("InlinedApi")
public void createNotification(String payload, String action, String notificationParameters) {
    NotificationManager notificationManager = (NotificationManager) getSystemService(
            Context.NOTIFICATION_SERVICE);

    String appName = getString(R.string.app_name);

    SharedPreferences settings = MyApplication.getInstance().getAppSharedPreferences();
    int notificatonID = settings.getInt("notificationID", 0); // allow multiple notifications //$NON-NLS-1$

    Intent intent = new Intent("android.intent.action.MAIN"); //$NON-NLS-1$
    intent.setClassName(this, getPackageName() + ".Main"); //$NON-NLS-1$
    intent.addCategory("android.intent.category.LAUNCHER"); //$NON-NLS-1$

    if (Services.Strings.hasValue(action)) {
        // call main as root of the stack with the action as intent parameter. Use clear_task like GoHome
        if (CompatibilityHelper.isApiLevel(Build.VERSION_CODES.HONEYCOMB))
            intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TASK | Intent.FLAG_ACTIVITY_NEW_TASK);
        else/*from w  ww . j ava 2  s.  c om*/
            intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP | Intent.FLAG_ACTIVITY_NEW_TASK);

        intent.putExtra(IntentParameters.NotificationAction, action);
        intent.putExtra(IntentParameters.NotificationParameters, notificationParameters);
        intent.setAction(String.valueOf(Math.random()));
    } else {
        // call main like main application shortcut
        intent.setFlags(0);
        intent.setAction("android.intent.action.MAIN");
    }

    PendingIntent pendingIntent = PendingIntent.getActivity(this, 0, intent, PendingIntent.FLAG_UPDATE_CURRENT);

    Notification notification = NotificationHelper.newBuilder(this).setWhen(System.currentTimeMillis())
            .setContentTitle(appName).setContentText(payload).setContentIntent(pendingIntent)
            .setStyle(new NotificationCompat.BigTextStyle().bigText(payload))
            .setDefaults(Notification.DEFAULT_ALL).setAutoCancel(true).build();

    notificationManager.notify(notificatonID, notification);

    SharedPreferences.Editor editor = settings.edit();
    editor.putInt("notificationID", ++notificatonID % 32); //$NON-NLS-1$
    editor.commit();
}

From source file:ca.etsmtl.applets.etsmobile.ScheduleWeekActivity.java

@Override
public boolean onOptionsItemSelected(MenuItem item) {
    Intent intent = null;// w  w w. j a  va  2 s.  c om
    switch (item.getItemId()) {
    case R.id.calendar_month_view:
        intent = new Intent(this, ScheduleActivity.class);
        intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
        break;
    case R.id.calendar_force_update:
        new CalendarTask(handler).execute(creds);
        break;

    default:
        break;
    }
    if (intent != null) {
        startActivity(intent);
        finish();
    }
    return true;
}

From source file:com.airbop.library.simple.AirBopGCMIntentService.java

private static void generateNotification(Context context, String title, String message, String url,
        String large_icon) {/*from  w  w w  .jav a  2  s  .c om*/

    //int icon = R.drawable.ic_stat_gcm;
    AirBopManifestSettings airBop_settings = CommonUtilities.loadDataFromManifest(context);

    int icon = airBop_settings.mNotificationIcon;

    long when = System.currentTimeMillis();
    NotificationManager notificationManager = (NotificationManager) context
            .getSystemService(Context.NOTIFICATION_SERVICE);

    //if ((title == null) || (title.equals(""))) {
    if (title == null) {
        title = airBop_settings.mDefaultNotificationTitle;
    }

    Intent notificationIntent = null;
    if ((url == null) || (url.equals(""))) {
        //just bring up the app
        if (context != null) {
            ClassLoader class_loader = context.getClassLoader();
            if (class_loader != null) {
                try {
                    if (airBop_settings.mDefaultNotificationClass != null) {
                        notificationIntent = new Intent(context,
                                Class.forName(airBop_settings.mDefaultNotificationClass));
                    }
                } catch (ClassNotFoundException e) {
                    // TODO Auto-generated catch block
                    e.printStackTrace();
                    //notificationIntent = new Intent(Intent.ACTION_VIEW);
                }
            }
        }

    } else {
        //Launch the URL
        notificationIntent = new Intent(Intent.ACTION_VIEW);
        notificationIntent.setData(Uri.parse(url));
        notificationIntent.addCategory(Intent.CATEGORY_BROWSABLE);
    }
    PendingIntent intent = null;
    // set intent so it does not start a new activity
    if (notificationIntent != null) {
        notificationIntent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP | Intent.FLAG_ACTIVITY_SINGLE_TOP);
        intent = PendingIntent.getActivity(context, 0, notificationIntent, 0);
    }

    Builder notificationBuilder = new NotificationCompat.Builder(context).setContentTitle(title)
            .setContentText(message).setLargeIcon(decodeImage(large_icon)).setWhen(when)
            .setStyle(new NotificationCompat.BigTextStyle().bigText(message));
    if (intent != null) {
        notificationBuilder.setContentIntent(intent);
    }
    if (icon != 0) {
        notificationBuilder.setSmallIcon(icon);
    }
    Notification notification = notificationBuilder.build();

    notification.flags |= Notification.FLAG_AUTO_CANCEL;
    notificationManager.notify(0, notification);

}

From source file:com.campusconnect.GoogleSignInActivity.java

private void firebaseAuthWithGoogle(final GoogleSignInAccount acct) {
    Log.d(TAG, "firebaseAuthWithGoogle:" + acct.getId());
    // [START_EXCLUDE silent]
    showProgressDialog();/*from  w w w.j  a  v a  2 s  . co  m*/
    // [END_EXCLUDE]
    AuthCredential credential = GoogleAuthProvider.getCredential(acct.getIdToken(), null);
    mAuth.signInWithCredential(credential).addOnCompleteListener(this, new OnCompleteListener<AuthResult>() {
        @Override
        public void onComplete(@NonNull Task<AuthResult> task) {
            Log.d(TAG, "signInWithCredential:onComplete:" + task.isSuccessful());
            // If sign in fails, display a message to the user. If sign in succeeds
            // the auth state listener will be notified and logic to handle the
            // signed in user can be handled in the listener.

            if (!task.isSuccessful()) {
                Log.w(TAG, "signInWithCredential", task.getException());
                Toast.makeText(GoogleSignInActivity.this, "Authentication failed.", Toast.LENGTH_SHORT).show();
            } else {
                Bundle params = new Bundle();
                params.putString("firebaseauth", "success");
                firebaseAnalytics.logEvent("login_firebase", params);
                personName = acct.getDisplayName();
                personEmail = acct.getEmail();
                personId = acct.getId();
                Log.i("sw32", personId + ": here");
                if (acct.getPhotoUrl() != null) {
                    personPhoto = acct.getPhotoUrl().toString() + "";
                    Log.d("photourl", personPhoto);
                } else
                    personPhoto = "shit";
                //                            mStatusTextView.setText(getString(R.string.signed_in_fmt, acct.getDisplayName()));
                SharedPreferences sharedpreferences = getSharedPreferences("CC", Context.MODE_PRIVATE);
                if (sharedpreferences.contains("profileId")) {
                    Intent home = new Intent(GoogleSignInActivity.this, HomeActivity2.class);
                    home.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
                    startActivity(home);
                    finish();
                } else {
                    //TODO: SIGN-IN
                    Retrofit retrofit = new Retrofit.Builder().baseUrl(MyApi.BASE_URL)
                            .addConverterFactory(GsonConverterFactory.create()).build();
                    MyApi myApi = retrofit.create(MyApi.class);
                    Log.i("sw32", personEmail + " : " + personId + " : "
                            + FirebaseInstanceId.getInstance().getToken());
                    MyApi.getProfileRequest body = new MyApi.getProfileRequest(personEmail, personId,
                            FirebaseInstanceId.getInstance().getToken());
                    Call<ModelGetProfile> call = myApi.getProfile(body);
                    call.enqueue(new Callback<ModelGetProfile>() {
                        @Override
                        public void onResponse(Call<ModelGetProfile> call, Response<ModelGetProfile> response) {
                            ModelGetProfile profile = response.body();
                            if (profile != null) {
                                if (profile.getResponse().equals("0")) {
                                    SharedPreferences sharedPreferences = getSharedPreferences("CC",
                                            MODE_PRIVATE);
                                    sharedPreferences.edit().putString("profileId", profile.getProfileId())
                                            .putString("collegeId", profile.getCollegeId())
                                            .putString("personId", personId)
                                            .putString("collegeName", profile.getCollegeName())
                                            .putString("batchName", profile.getBatchName())
                                            .putString("branchName", profile.getBranchName())
                                            .putString("sectionName", profile.getSectionName())
                                            .putString("profileName", personName)
                                            .putString("email", personEmail)
                                            .putString("photourl", profile.getPhotourl()).apply();
                                    Log.d("profileId", profile.getProfileId());
                                    Intent home = new Intent(GoogleSignInActivity.this, HomeActivity2.class);
                                    home.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
                                    startActivity(home);
                                    finish();
                                } else {
                                    try {
                                        String decider = Branch.getInstance().getLatestReferringParams()
                                                .getString("+clicked_branch_link");
                                        Intent registration = new Intent(GoogleSignInActivity.this,
                                                RegistrationPageActivity.class);
                                        if (decider.equals("false")) {
                                            registration.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
                                            registration.putExtra("personName", personName);
                                            registration.putExtra("personEmail", personEmail);
                                            registration.putExtra("personPhoto", personPhoto);
                                            registration.putExtra("personId", personId);

                                            startActivity(registration);
                                            finish();
                                            Log.d("branch", "regester called");
                                        }
                                    } catch (JSONException e) {
                                        e.printStackTrace();
                                    }
                                }
                            }
                        }

                        @Override
                        public void onFailure(Call<ModelGetProfile> call, Throwable t) {

                        }
                    });

                }
            }
            // [START_EXCLUDE]
            //Branch login
            try {
                String decider = Branch.getInstance().getLatestReferringParams()
                        .getString("+clicked_branch_link");
                if (decider.equals("true")) {

                    if (Branch.isAutoDeepLinkLaunch(GoogleSignInActivity.this)) {

                        final String collegeId = Branch.getInstance().getLatestReferringParams()
                                .getString("collegeId");
                        final String collegeName = Branch.getInstance().getLatestReferringParams()
                                .getString("collegeName");
                        final String batchName = Branch.getInstance().getLatestReferringParams()
                                .getString("batch");
                        final String branchName = Branch.getInstance().getLatestReferringParams()
                                .getString("branch");
                        final String sectionName = Branch.getInstance().getLatestReferringParams()
                                .getString("sectionName");

                        String brachCoursesId = Branch.getInstance().getLatestReferringParams()
                                .getString("coursesId");
                        Log.d("brancS:", brachCoursesId);
                        String replace = brachCoursesId.replace("[", "");
                        String replace1 = replace.replace("]", "");
                        final List<String> coursesId = new ArrayList<String>(
                                Arrays.asList(replace1.split("\\s*,\\s*")));
                        Log.d("brancL:", coursesId.toString());

                        Retrofit branchRetrofit = new Retrofit.Builder().baseUrl(FragmentCourses.BASE_URL)
                                .addConverterFactory(GsonConverterFactory.create()).build();
                        MyApi myApi = branchRetrofit.create(MyApi.class);
                        final MyApi.getProfileIdRequest request;
                        Log.d("firebase", FirebaseInstanceId.getInstance().getId());
                        request = new MyApi.getProfileIdRequest(personName, collegeId, batchName, branchName,
                                sectionName, personPhoto, personEmail, FirebaseInstanceId.getInstance().getId(),
                                personId);
                        Call<ModelSignUp> modelSignUpCall = myApi.getProfileId(request);
                        modelSignUpCall.enqueue(new Callback<ModelSignUp>() {
                            @Override
                            public void onResponse(Call<ModelSignUp> call, Response<ModelSignUp> response) {
                                ModelSignUp signUp = response.body();
                                if (signUp != null) {
                                    profileId = signUp.getKey();
                                    SharedPreferences sharedPreferences = getSharedPreferences("CC",
                                            MODE_PRIVATE);
                                    sharedPreferences.edit().putString("profileId", profileId)
                                            .putString("collegeId", collegeId).putString("personId", personId)
                                            .putString("collegeName", collegeName)
                                            .putString("batchName", batchName)
                                            .putString("branchName", branchName)
                                            .putString("sectionName", sectionName)
                                            .putString("profileName", personName)
                                            .putString("email", personEmail).putString("photourl", personPhoto)
                                            .apply();
                                    Log.d("branch login sucess", profileId);

                                    Retrofit retrofit = new Retrofit.Builder().baseUrl(FragmentCourses.BASE_URL)
                                            .addConverterFactory(GsonConverterFactory.create()).build();

                                    MyApi branchMyApi = retrofit.create(MyApi.class);
                                    MyApi.subscribeCourseRequest subscribeCourseRequest = new MyApi.subscribeCourseRequest(
                                            profileId, coursesId);
                                    Call<ModelSubscribe> courseSubscribeCall = branchMyApi
                                            .subscribeCourse(subscribeCourseRequest);
                                    courseSubscribeCall.enqueue(new Callback<ModelSubscribe>() {
                                        @Override
                                        public void onResponse(Call<ModelSubscribe> call,
                                                Response<ModelSubscribe> response) {
                                            ModelSubscribe subscribe = response.body();
                                            if (subscribe != null) {
                                                Log.d("branch response:", subscribe.getResponse());
                                                SharedPreferences sharedPreferences = getSharedPreferences("CC",
                                                        MODE_PRIVATE);
                                                sharedPreferences.edit()
                                                        .putString("coursesId", coursesId.toString()).apply();
                                            }
                                            Intent intent_temp = new Intent(getApplicationContext(),
                                                    HomeActivity2.class);
                                            intent_temp.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
                                            startActivity(intent_temp);
                                            Log.d("branch", "home activity");
                                            Bundle params = new Bundle();
                                            params.putString("course_subscribe", "success");
                                            firebaseAnalytics.logEvent("course_subscribe", params);
                                            finish();
                                        }

                                        @Override
                                        public void onFailure(Call<ModelSubscribe> call, Throwable t) {
                                            Log.d("couses", "failed");
                                        }
                                    });

                                }
                            }

                            @Override
                            public void onFailure(Call<ModelSignUp> call, Throwable t) {
                                Log.d("branch login", "failed");
                            }
                        });

                    } else {
                        Log.e("BRanch", "Launched by normal application flow");
                    }
                }
            } catch (JSONException e) {
                e.printStackTrace();
            }
            hideProgressDialog();
            // [END_EXCLUDE]

        }

    });
}

From source file:ca.ualberta.cs.cmput301w15t04team04project.EditItemActivity.java

/**
 * <ol>/*from w ww . j  ava 2  s.c  om*/
 * <li type = "square">The item of the option menu will call this function to confirm the change.
        
 * <ul>
 * <li>It will find the needed views by their id
 * <li>It will test the user chose to either edit or add an Item
 * <li>It will save the change that a user made
 * </ul>
 * </ol>
 * @param item The option item which belongs to the option menu.
 * @author Yufei Zhang
 * @version 1.0
 * @since 2015-03-02
 */
public void confirm(MenuItem item) {
    /**
     * we need to add code here doing the following things: 1. Add a new
     * item to the current claim 2. Update the changes of the chosen item
     **/

    /**
     * this part should be in controller. Chenrui
     */
    // get the views
    boolean completeCheck = true;

    EditText itemName = (EditText) findViewById(R.id.itemNameEditText);

    DatePicker itemDateDatePicker = (DatePicker) findViewById(R.id.itemDateDatePicker);

    Calendar calendar = Calendar.getInstance();
    calendar.set(itemDateDatePicker.getYear(), itemDateDatePicker.getMonth(),
            itemDateDatePicker.getDayOfMonth());

    Spinner itemCategorySpinner = (Spinner) findViewById(R.id.itemCategorySpinner);

    Spinner currencyUnitsSpinner = (Spinner) findViewById(R.id.currencyUnitsSpinner);
    EditText itemCurrencyEeditText = (EditText) findViewById(R.id.itemCurrencyEditText);

    EditText fragmentEditItem2DiscriptionEditText = (EditText) findViewById(
            R.id.fragmentEditItem2DiscriptionEditText);

    ImageButton imageButton = (ImageButton) findViewById(R.id.addRecieptImageButton);

    // create an item

    if (addEditItemStatus == 0) {
        Item newitem = new Item(itemName.getText().toString());
        newitem.setItemDate(calendar.getTime());

        newitem.setItemCategory(itemCategorySpinner.getSelectedItem().toString());

        String tempAmountStr = itemCurrencyEeditText.getText().toString();
        int tempAmountInt = 0;
        try {
            tempAmountInt = Integer.valueOf(tempAmountStr);
        } catch (NumberFormatException e) {
            tempAmountInt = 0;
        }
        Currency tempCurrency = new Currency(currencyUnitsSpinner.getSelectedItem().toString(), tempAmountInt);
        newitem.setItemCurrency(tempCurrency);

        newitem.setItemDescription(fragmentEditItem2DiscriptionEditText.getText().toString());

        // controller.addItem(this.item);
        if (receiptFlag == 1) {
            newitem.setReceipBitmap(bitmap);

        }
        Toast.makeText(this, "added", Toast.LENGTH_LONG).show();

        controller.addItem(newitem);
        UpdateThread update = new UpdateThread(controller.getClaim());
        update.start();

        /**
         * part end here
         */
    } else {
        Toast.makeText(this,
                controller.getClaim().getClaim() + itemId + controller.getClaim().getItems().size(),
                Toast.LENGTH_LONG).show();
        controller.getClaim().getPosition(itemId).setItemDate(calendar.getTime());
        controller.getClaim().getPosition(itemId).setItemName(itemName.getText().toString());
        controller.getClaim().getPosition(itemId)
                .setItemCategory(itemCategorySpinner.getSelectedItem().toString());
        String tempAmountStr = itemCurrencyEeditText.getText().toString();
        int tempAmountInt = 0;
        try {
            tempAmountInt = Integer.valueOf(tempAmountStr);
        } catch (NumberFormatException e) {
            tempAmountInt = 0;
        }
        Currency tempCurrency = new Currency(currencyUnitsSpinner.getSelectedItem().toString(), tempAmountInt);
        controller.getClaim().getPosition(itemId).setItemCurrency(tempCurrency);

        controller.getClaim().getPosition(itemId)
                .setItemDescription(fragmentEditItem2DiscriptionEditText.getText().toString());
        if (receiptFlag == 1) {
            controller.getClaim().getPosition(itemId).setReceipBitmap(bitmap);

        }
        UpdateThread update = new UpdateThread(controller.getClaim());
        update.start();

    }

    Intent intent = new Intent(EditItemActivity.this, OneClaimActivity.class);
    intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
    intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
    intent.putExtra("MyClaimName", claimName);
    startActivity(intent);
    finish();
}

From source file:com.xargsgrep.portknocker.activity.EditHostActivity.java

private void returnToHostListActivity(Boolean saveResult) {
    Intent hostListIntent = new Intent(this, HostListActivity.class);
    hostListIntent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
    if (saveResult != null)
        hostListIntent.putExtra(KEY_SAVE_HOST_RESULT, saveResult);
    startActivity(hostListIntent);/* w  w w  .  j ava2 s . c o  m*/
}