【问题标题】:Android Service sending bundle data to activity is NULL向活动发送捆绑数据的 Android 服务为 NULL
【发布时间】:2015-07-25 04:19:34
【问题描述】:

我正在尝试将捆绑数据从我的服务发送到我的活动,url 和 id 仅位图不起作用,有效。我不知道为什么?

服务等级:

String imgUrl = ".....img1.jpg";
String imageId = "111";
// Construct pending intent to serve as action for notification item
Intent intent = new Intent(this, ImagePreviewActivity.class);

intent.putExtra("url", imgUrl);
intent.putExtra("id", imageId);
intent.putExtra("bitmap", resizedBitmap);

PendingIntent pIntent = PendingIntent.getActivity(this, 0, intent, 0);

ImagePreviewActivity:

Bundle extras = getIntent().getExtras();
if(extras != null)
{

    imgUrl  = extras.getString("url");
    imgId   = getIntent().getStringExtra("id");
    mBitmap = getIntent().getParcelableExtra("bitmap");

    Log.i(TAG, "Bundle ->> imgUrl => " + imgUrl + " | imgId => " + imgId);

    //setImageToCarViewFromUrl(imgUrl);
    setImageToCarViewFromBitmap(mBitmap);
}
else if(getIntent().getParcelableExtra("bitmap") != null)
{
    mBitmap = getIntent().getParcelableExtra("bitmap");
    setImageToCarViewFromBitmap(mBitmap);
}
else
{
    //Image not Ready
    dialogImagesNotReady(false);
}

结果:捆绑 ->> imgUrl => null | imgId => null

只有 mBitmap 有效!

【问题讨论】:

  • 调用getActivity时使用不同的requestCode

标签: java android android-activity service bundle


【解决方案1】:

我认为您确实将 String 而不是 Bundle。你应该打电话

getIntent().getStringExtra("你的钥匙");

如果你想要 bundle(getIntent().getExtras() 上的值),你应该把它放在一个 Bundle 类中

捆绑捆绑 = 新捆绑();

bundle.putString("key","value");

intent.putExtra("key",bundle)

【讨论】:

    猜你喜欢
    • 2012-12-30
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多