小编Jba*_*d26的帖子

没有调用IntentService

我试图从一个Activity中的onCreate发送一个Intent来启动一个IntentService.但是,永远不会收到IntentService的onHandleIntent.我尝试使用Intent-filters更改Manifest,但似乎没有任何工作.没有抛出异常,但根本不调用IntentService.

这是onCreate

@Override
public void onCreate(Bundle savedInstanceState)
{

    super.onCreate(savedInstanceState);
    setContentView(R.layout.main);
    db = new TwitterDB(this);
    String[] columns = new String[1];
    columns[0] = TwitterDB.TEXT;
    tAdapter = new SimpleCursorAdapter(this, 0, null, columns, null, 0); 
    tweets = (ListView)findViewById(R.id.listtwitter);
    tweets.setAdapter(tAdapter);

    Intent intent = new Intent(this, SyncService.class);
    intent.putExtra("action", SyncService.TWITTER_SYNC);
    this.startService(intent);

}
Run Code Online (Sandbox Code Playgroud)

这是IntentService类的创建者和onHandleIntent,我知道它没有被调用,因为logcat从不显示"检索到的意图".也没有调用构造函数(那里有一个日志调用,但我删除了它.

public SyncService(){
    super("SyncService");
    twitterURI = Uri.parse(TWITTER_URI);
    Log.i("SyncService", "Constructed");
}

@Override
public void onHandleIntent(Intent i){
    int action = i.getIntExtra("action", -1);
    Log.i("SyncService", "Retrieved intent");
    switch (action){
        case TWITTER_SYNC:
            try{
                url = new URL(twitterString);
                conn = (HttpURLConnection)url.openConnection(); …
Run Code Online (Sandbox Code Playgroud)

service android intentfilter intentservice

7
推荐指数
2
解决办法
5597
查看次数

从UDP数据包获取IP地址和端口

我有一个使用netcat的服务器设置:

nc -l 4444 -u
Run Code Online (Sandbox Code Playgroud)

和客户:

nc 127.0.0.1 4444 -u
Run Code Online (Sandbox Code Playgroud)

我使用localhost因为它们都在我的计算机上,但如果客户端移动到另一台计算机,netcat是否有办法告诉我客户端的IP地址和端口号?

ip port networking udp netcat

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

#define的奇怪行为

我在C++中有这个代码:

#include <string>
#include <iostream>

int const foo = 1;
int const bar = 0;

#define foo bar
#define bar foo

int main()
{
  std::cout << foo << std::endl;
  std::cout << bar << std::endl;
}
Run Code Online (Sandbox Code Playgroud)

它产生这个输出:

bash-3.2$ ./a.out
1
0
Run Code Online (Sandbox Code Playgroud)

我不明白为什么这是输出.

c++ c-preprocessor

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