启动网页和来自同一类别的新活动
问题描述:
我只想在按下按钮时打开URL并打开新活动,但只显示新活动。启动网页和来自同一类别的新活动
public void rate (View v){
AppLink= new Intent(Intent.ACTION_VIEW,Uri.parse("http://www.google.com"));
i=new Intent (this, Lev7Activity.class);
startService(AppLink);
startActivity(i);
this.finish();
}
答
使用startActivity没有startService打开网页
public void rate (View v){
AppLink= new Intent(Intent.ACTION_VIEW,Uri.parse("http://www.google.com"));
i=new Intent (this, Lev7Activity.class);
startActivity(AppLink);
startActivity(i);
this.finish();
}
答
您已经使用startService启动浏览器的活动。 startService只能用于启动后台任务(扩展Service的类)。 如果你想开始一个新的活动,请使用startActivity代替:
public void rate (View v){
AppLink= new Intent(Intent.ACTION_VIEW,Uri.parse("http://www.google.com"));
i=new Intent (this, Lev7Activity.class);
startActivity(AppLink);
startActivity(i);
this.finish();
}
如果您尝试它,你会发现,它也不会工作 –