我有这个:
@Override
public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
String urlCorrecta="";
//Si se escoge la posicion de el arreglo 0 abre la clase LasVegas
if (position == 0)
{
Intent intent = new Intent(this, MainActivity.class);
startActivity(intent);
urlCorrecta = "souphttpsrc location=http://69.54.28.188:7878/mjpg/video.mjpg ! multipartdemux single-stream=true ! jpegdec ! autovideosink sync=false ";
}
//Si se escoge la posicion de el arreglo 1 abre la clase LosGuayabos
else if (position == 1)
{
Intent intent = new Intent(this, LosGuayabos.class);
startActivity(intent);
urlCorrecta = "souphttpsrc location=http://rax1.bsn.net/mjpg/video.mjpg?streamprofile=Balanced ! multipartdemux single-stream=true ! jpegdec ! autovideosink sync=false ";
}
//Si se escoge la posicion de el arreglo 2 abre la clase RegionalNorte
else if (position == 2)
{
Intent intent = new Intent(this, RegionalNorte.class);
startActivity(intent);
urlCorrecta = "souphttpsrc location=http://trackfield.webcam.oregonstate.edu/mjpg/video.mjpg ! multipartdemux single-stream=true ! jpegdec ! autovideosink sync=false ";
}
//Si se escoge la posicion de el arreglo 3 abre la clase RegionalSur
else if (position == 3)
{
Intent intent = new Intent(this, RegionalSur.class);
startActivity(intent);
urlCorrecta = "souphttpsrc location=http://wmccpinetop.axiscam.net/mjpg/video.mjpg ! multipartdemux single-stream=true ! jpegdec ! autovideosink sync=false ";
}
}
我想将String urlCorrecta的值传递给位于MainActivity类中的String VIDEO_IN_PIPELINE。
public class MainActivity extends ActionBarActivity implements SurfaceHolder.Callback{
private final String VIDEO_IN_PIPELINE = VALUE OF THE STRING urlCorrecta;
private final String HOST_IP = "192.168.1.167";
}
如何将其他类中的String转换为此类?
非常感谢阅读。
答案 0 :(得分:1)
使用额外内容:
Intent intent = new Intent(this, LosGuayabos.class);
intent.putExtra("myString", myString);
startActivity(intent);
然后你只需要在onCreate方法中获得意图:
String myString = getIntent().getExtras().getString("myString");
答案 1 :(得分:1)
从一个活动发送字符串
Intent intent = new Intent(CurrentActivity.this, ReceiverActivity.class);
intent.puExtra("key","String Value");
startActivity(intent);
在ReceiverActivity
Intent intent = getIntent();
String str = intent.getExtra().getString("key");
答案 2 :(得分:1)
要将其传递给其他Activity
,请在新Intent
中将其作为额外内容添加:
Intent intent = new Intent(this, MainActivity.class);
intent.putExtra("urlCorrecta", "souphttpsrc location=http://rax1.bsn.net/mjpg/video.mjpg?streamprofile=Balanced ! multipartdemux single-stream=true ! jpegdec ! autovideosink sync=false ");
startActivity(intent);
要在MainActivity
的{{1}}:
onCreate()
试试这个。这将有效。