在android中使用String作为Url

时间:2013-07-11 16:27:22

标签: android string url android-activity

我在android中有一个字符串,在这个字符串中有一个url。 所以现在将该字符串输入到put.extra中,因为我想将该字符串赋予2. Activity。

现在在2.活动中我想重新接收我的字符串并使用字符串中的url作为新的/其他字符串。

我怎么能这样做?

对于我自己,我做了一个你可以在这下看到的例子,但是当我运行这个应用程序时,在第二个活动中得到一个空白页面!这个代码怎么了?

代码示例:

活动字符串定义:

private static final String TAG_PURL = "url";

额外和新的意图:

Bundle bundle = new Bundle ();
            bundle.putSerializable(TAG_PURL, purl);

            // Starting new intent
            Intent postin = new Intent(getApplicationContext(), post.class);          
            postin.putExtras(bundle);
            startActivity(postin);
        }
    });

额外收回:

Intent postin = getIntent();

            Bundle bundle = this.getIntent().getExtras();
            String purl = (String) bundle.getSerializable (TAG_PURL);

在新字符串中使用purl String:

private static final String url = TAG_PURL ;

1 个答案:

答案 0 :(得分:0)

如果您愿意,可以尝试:

private static final String TAG_PURL = "url";

 Intent i = new Intent(A.this, B.class);
 i.putExtra("URL", TAG_PURL);
 startActivity(i);

您可以从您的活动中获取此信息,例如:

 Bundle extras = getIntent().getExtras();
 String url= extras.getInt("URL");