小编hac*_*cke的帖子

Android意图语法

在我试图找到如何在我的应用程序中启动新意图时,我遇到了几种方法来表达它.

此语法返回运行时错误,即ActivityNotFound异常

Intent in = new Intent("com.something.something"); 
Run Code Online (Sandbox Code Playgroud)

当然我的android清单包含intent过滤器中的一个动作:

<activity
        android:name=".SecondActivity"
        android:label="@string/title_activity_second" >
        <intent-filter>
            <action android:name="com.something.something" />

            <category android:name="android.intent.category.LAUNCHER" />
        </intent-filter>
    </activity> 
Run Code Online (Sandbox Code Playgroud)

这种格式有效:

Intent in = new Intent(MainActivity.this, SecondActivity.class); 
Run Code Online (Sandbox Code Playgroud)

我也尝试过以下方法:

Intent in = new Intent(this, SomeActivity.class); 
Run Code Online (Sandbox Code Playgroud)

这是我正在阅读的一本书中推荐的.这将返回运行时错误,activitynotfound

这个让Eclipse无限地在setClass和setClassName之间来回抛出:

 Intent in = new Intent().setClass(this, SecondActivity.class);
Run Code Online (Sandbox Code Playgroud)

我在onclick方法中使用它:

ok.setOnClickListener(new View.OnClickListener()
    {

        @Override
        public void onClick(View v)
        {

            Intent in = new Intent(MainActivity.this, SecondActivity.class);
            startActivity(in);
        }
    });
}
Run Code Online (Sandbox Code Playgroud)

这些和为什么只有其中一个为我工作有什么区别?

问候/ M.

syntax android android-intent

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

使用Chrome多功能框可以快速翻译

我刚刚意识到Omnibox有快速命令,我想知道是否有任何谷歌命令翻译.说我想从中文翻译成瑞典语,是否有可能写出类似于你的东西 - 从中​​文到瑞典语?

google-chrome google-translate omnibox

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

在Python中启用和禁用调试消息

我目前正在学习Python,并且知道幕后发生了什么,我写了很多打印输出.看到回去评论我开始编写模块的所有消息都是一件大惊小怪的事情,我在方法中设置了我想要使用它们的所有消息,然后使用布尔值来关闭和打开消息.问题是,我得到无打印输出而不是我的调试消息,这不是很优雅.有办法解决这个问题吗?

一些示例代码:

def setDebug(bool):
    '''
    Toggles the debug messages
    '''

    global _debug
    _debug = bool


def setNewMsg(msg):
    '''
    Appends a new debug message to the list
    '''
    global _debugMsg
    _debugMsg.append(msg)

def getDebugMsg(index):
    '''
    Takes an int for a parameter and returns the debug message needed
    '''
    global _debug
    global _debugMsg

    if _debug == True:
        return _debugMsg[index] 
    else: 
        return
Run Code Online (Sandbox Code Playgroud)

python debugging nonetype

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