小编JoP*_*JoP的帖子

addToBackStack不起作用,关闭活动而不是弹出片段

我有一个问题,我无法在任何地方找到解决方案.

当我按下后退按钮时,我的应用程序不会返回到上一个片段,而是关闭活动.

我有一个显示4个片段的活动:[1],[2],[3],[4].我可以使用操作栏在前3个片段之间切换,我不想将它们添加到后台堆栈.

片段[4]是片段[3]中选择的项目的详细视图.当我按下[4]时,我想返回片段[3],而不是关闭应用程序.

过渡是以这种方式完成的,其中放置了碎片的活动:

private void replaceFragment(Fragment fragment, boolean toBackStack){

    if(fragment != null){

        FragmentTransaction fragmentTransaction = getFragmentManager().beginTransaction();
        fragmentTransaction.replace(R.id.container, fragment);

        if(toBackStack)
            fragmentTransaction.addToBackStack(null);

        fragmentTransaction.commit();
    }
}
Run Code Online (Sandbox Code Playgroud)

除非转换是从[3]到[4],否则toBackStack始终为false.

如果我在每次转换中都将toBackStack传递给true,那么活动无论如何都会关闭.

android android-fragments android-activity back-stack

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

从eclipse运行app时android手机重启

这里奇怪的问题.

每次我从eclipse运行app时,我的手机都会重启.应用程序不安装.

编辑:重新启动我尝试安装应用程序,如果我尝试'adb install apppackage.apk'

EDIT2:当我尝试从Android Market安装应用程序时,fix_permissions无效

有任何想法吗?

android adb

7
推荐指数
0
解决办法
976
查看次数

setTimeout并不总是在Greasemonkey中工作

我发现了很多类似的问题,但没有一个问题,没有正确的解决方案.这是一个非常奇怪的问题.

我有一个简单的Greasemonkey脚本来测试问题:

// ==UserScript==
// @name        testdiddio
// @namespace   http://userscripts.org/users/useridnumber
// @include     https://www.google.it/
// @version     1
// ==/UserScript==


function wait(){
    console.info("wait");
    setTimeout(wait,1000);
}

console.info("start");
wait();
Run Code Online (Sandbox Code Playgroud)

这是firebug的输出:

start
wait
wait
wait
wait
Run Code Online (Sandbox Code Playgroud)

wait()函数被调用4次然后停止.如果我将超时设置为100毫秒,则呼叫似乎至少工作10/15秒然后停止.

我正在使用:Firefox 12.0 Greasemonkey 0.9.19

greasemonkey settimeout

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

如何防止用户使用dotnet核心和RESTful API访问其他用户的数据?

我正试图找到一个简单问题的最佳解决方案,这个问题并没有在很大程度上讨论过.

我的应用程序有很多用户可以创建和编辑数据.用户应该只能看到和编辑他的数据,而不是其他数据.

想想有餐厅A和菜单菜单A的爱丽丝,以及有餐厅B和菜单菜单B的鲍勃.

我有CRUD餐馆和菜单的API,我可以很容易地只授权具有正确声明和角色的登录用户.我现在要做的是阻止Bob访问Alice的餐厅或菜单,反之亦然.例如,Bob应该被授权PUT /api/restaurants/B但应该是未经授权的PUT /api/restaurants/A甚至是PUT /api/restaurants/A/menus/x

一个可能的解决方案是这里提供的ASP.NET MVC属性,只允许用户编辑他/她自己的内容.此解决方案需要创建自定义Authorize属性以主动检查记录的用户是否是所访问实体的专有权.实体具有userId字段以检查发出请求的用户是否是数据的所有者.这个解决方案很干净,但缺乏一些功能.模型中的每个实体都应该有一个userId字段,并且只能由所有者访问或者我需要导航到授权模型的根实体的每个实体(例如,访问菜单我需要查询父实体Restaurant来检查如果MenuB在用户拥有的餐馆内).要实现多个所有者(例如餐馆经理),逻辑将会复杂得多.我也担心这里的开销,因为基本上每个调用都需要做一些查询来检查数据访问,但这可能不是问题.

有最好的做法吗?

.net api authorization

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

getChildCount()在ListView上返回0

我需要检查ListView上的所有元素,只将标签设置为其中一个.我无法编辑数据库或适配器,我只想滚动ListView以执行检查并在TextView上设置字符串.

@Override
protected void onResume(){
    super.onResume();
    ...
    cursor = getCursor();
    startManagingCursor(cursor);
    adapter = new SimpleCursorAdapter(this,R.layout.profile_item_layout,cursor,from,to);
    lst_profiles.setAdapter(adapter);
    SharedPreferences customSharedPreference = PreferenceManager.getDefaultSharedPreferences(ProfilerActivity.this.getApplicationContext());
    long current = customSharedPreference.getLong(ProfileManager.CURRENT, -1);
    toast(lst_profiles.getChildCount()); //display 0
    if(current!=-1){
        for(int i=0;i<lst_profiles.getChildCount();i++){
            if(lst_profiles.getItemIdAtPosition(i)==current)
                ((TextView)lst_profiles.getChildAt(i).findViewById(R.id.activeLabel)).setText(getString(R.string.active));
            else
                ((TextView)lst_profiles.getChildAt(i).findViewById(R.id.activeLabel)).setText("");
        }       
    }
}
Run Code Online (Sandbox Code Playgroud)

我能怎么做?我需要等一下吗?

PS Obviusly ListView不为空.

android listview zero

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