小编vin*_*thp的帖子

如何删除android中共享首选项中保存的数据?

我在我的应用程序中使用facebook api.它的工作正常我可以登录并发布在墙上.但我无法删除登录信息.

这是代码

   public boolean saveCredentials(Facebook facebook) {
        Editor editor = getApplicationContext().getSharedPreferences(KEY, Context.MODE_PRIVATE).edit();
        editor.putString(TOKEN, facebook.getAccessToken());
        editor.putLong(EXPIRES, facebook.getAccessExpires());
        return editor.commit();
    }

    public boolean restoreCredentials(Facebook facebook) {
        SharedPreferences sharedPreferences = getApplicationContext().getSharedPreferences(KEY, Context.MODE_PRIVATE);
        facebook.setAccessToken(sharedPreferences.getString(TOKEN, null));
        facebook.setAccessExpires(sharedPreferences.getLong(EXPIRES, 0));
        return facebook.isSessionValid();
    }

    public boolean removeCredentials()
    {
        SharedPreferences prefs = getApplicationContext().getSharedPreferences(KEY, Context.MODE_PRIVATE);

            facebook.setAccessToken(prefs.getString("", null));
        facebook.setAccessExpires(prefs.getLong("", 0));
        Editor editor = prefs.edit(); 
        editor.clear();
        editor.commit(); 
        return true; 
    }
Run Code Online (Sandbox Code Playgroud)

尚未通过调用removeCredentials()方法删除共享首选项详细信息.它只是在Facebook墙上发布消息.

我只是想删除保存的详细信息,如果用户再次请求在墙上发布消息,那么我需要弹出登录屏幕.

谢谢你的帮助

android facebook sharedpreferences

2
推荐指数
1
解决办法
1万
查看次数

如何在DatePickerDialog.OnDateSetListener中获取OnClick?

我使用以下方法弹出对话框来选择日期.

private DatePickerDialog.OnDateSetListener mDateSetListener =
        new DatePickerDialog.OnDateSetListener() {

            public void onDateSet(DatePicker view, int year, 
                                  int monthOfYear, int dayOfMonth) {
                dobYear = year;
                dobMonth = monthOfYear;
                dobDay = dayOfMonth;
                if(isEighteenYearOld()){
                   //display the current date
                    dateDisplay();
                } else{
                   Toast.makeText(mContext, "You must be 18 year old", Toast.LENGTH_SHORT).show();
                }  
            } 

        };
Run Code Online (Sandbox Code Playgroud)

我知道onDateSet我们可以获得所选日期.但我正在尝试的是,如果选择的日期小于18年,我需要提醒用户.我已经尝试了上面的代码,但它关闭了对话框并返回到活动.

我想留在对话框中,直到用户选择18岁的日期.我不知道如何在对话框中获取onclick事件?

android datepicker

2
推荐指数
1
解决办法
1万
查看次数

如何使用AsyncTask获取GPS位置?

我已经看到了很多这类问题的答案,但它与我的任务无关.我想在后台获取GPS位置,但我得到的例外是Cant Create Handler Inside Thread That Has Not Called Looper Prepare in AndroidmlocManager.requestLocationUpdates( LocationManager.GPS_PROVIDER, 0, 0, mlocListener);.

public class GPSLocation extends AsyncTask<Void, Void, Void>
    {  
        @Override
        protected void onPreExecute()
        {  
            super.onPreExecute(); 
            progressDialog = new ProgressDialog(RoadMaintenanceActivity.this);
            progressDialog.setCancelable(true);
            progressDialog.setMessage("Getting GPS Location...");
            progressDialog.setProgressStyle(ProgressDialog.STYLE_SPINNER);
            progressDialog.setProgress(1);
            progressDialog.show();

        } 
        @Override 
        protected void onProgressUpdate(Void... values) {
            super.onProgressUpdate(values);
            // Things to be done while execution of long running operation is in progress. For example updating ProgessDialog
         }

        @Override 
        protected void onPostExecute(Void result)
        { 

                progressDialog.cancel(); …
Run Code Online (Sandbox Code Playgroud)

android android-asynctask

1
推荐指数
1
解决办法
6787
查看次数

如何以高效的方式为IOS应用程序创建Sqlite数据库?

我已经构建了一个Android应用程序,现在是构建IOS应用程序的时候了.我是IOS App开发的新手.我设法完成了所有UI设计部分,我正在编写后端部分.在我的应用程序中,我使用的是Sqlite数据库,并且每个View都与许多View控制器对话.所以我想有一个类(Java),它关注创建,插入,删除等.如果我需要从数据库中获取数据,那么我必须调用该类来访问数据库.有没有办法这样做.

要么

我想知道如何以有效的方式创建sqlite数据库.因为我的应用完全基于数据库.

谢谢你的帮助.

sqlite iphone objective-c ios

1
推荐指数
1
解决办法
9541
查看次数

动画UIView无法按预期工作

在我的应用程序中,我使用的UIView是包含UITableView,ButtonsLabels在其中.它创建使用Storyboard.当用户单击导航栏按钮时,UIView将显示从顶部到特定高度的动画,如果再次单击它,则会隐藏带有动画的UIView(从该高度到顶部).同样的UIActionView.

如果没有记录,它可以正常工作UITableView.但如果它有任何记录,则调用[self hideBasket]UIView时会从视图底部显示到顶部(Not Hidden).

//隐藏篮子代码

-(void)hideBasket{
    /*Finished Hiding the Basket
     [self.view sendSubviewToBack:_shoppingCartView];
     [_shoppingCartView setHidden:YES];
     _isShoppingCartSeen = NO;*/

    CGRect basketFrame = _shoppingCartView.frame;
    basketFrame.origin.y = -basketFrame.size.height;

    [UIView animateWithDuration:1.0 delay:0.0 options:UIViewAnimationOptionCurveEaseOut animations:^{
        _shoppingCartView.frame = basketFrame;
    } completion:^(BOOL finished) {
        // Finished Hiding the Basket
        //[self.view sendSubviewToBack:_shoppingCartView];
       // [_shoppingCartView setHidden:YES];
        _isShoppingCartSeen = NO;
}]; 
Run Code Online (Sandbox Code Playgroud)

//显示篮子代码

-(void)showBasket{

    /*[self.view bringSubviewToFront:_shoppingCartView];
    [_shoppingCartView setHidden:NO];
    _isShoppingCartSeen = YES;*/

    CGRect basketFrame = …
Run Code Online (Sandbox Code Playgroud)

objective-c uiview uiviewanimation ios

1
推荐指数
1
解决办法
642
查看次数