我正在使用意图和switch case 2使用相同的webview加载两个不同的URL。它工作正常但现在如何在插页式广告出现后加载两个不同的网址。在此时间点广告显示和关闭后,我得到一个空白的webview intead按钮各自的URL。
任何人都可以修改我的代码。
家庭活动。
int attack_grid[10][10] = { {0} };
void drawAttackGrid()
{
int i, j, x = 0, y = 0;
for (i = 0; i <= 10 - 1; i++) {
for (j = 0; j <= 10 - 1; j++) {
if (attack_grid[x][y] > 0)
printf(" * ");
else if (attack_grid[x][y] < 0)
printf(" ~ ");
else
printf(" ? ");
y++;
}
printf("\n");
x++;
}
}
}
这是我的第二项活动,
enter code here
public class home extends AppCompatActivity {
AdView mAdview3;
private InterstitialAd interstitialAd;
public RatingBar ratingbar;
Button button;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_home);
ratingbar = (RatingBar) findViewById(R.id.ratingBar);
Button button = (Button) findViewById(R.id.button3);
MobileAds.initialize(this, "ca-app-pub-3940256099942544~3347511713"); //Main_app id
mAdview3 = (AdView) findViewById(R.id.adView);
AdRequest adRequest = new AdRequest.Builder().addTestDevice("E4D1201527AD69E0FD7A0551277A5232").build();
mAdview3.loadAd(adRequest);
interstitialAd = new InterstitialAd(this);
interstitialAd.setAdUnitId("ca-app-pub-3940256099942544/1033173712");
AdRequest adRequest1 = new AdRequest.Builder().addTestDevice("E4D1201527AD69E0FD7A0551277A5232").build();
interstitialAd.loadAd(adRequest1);
interstitialAd.setAdListener(new AdListener() {
public void onAdClosed() {
startActivity(new Intent(home.this, playerzpot_team.class));
}
});
button.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
if (interstitialAd.isLoaded()) {
interstitialAd.show();
} else {
startActivity(new Intent(home.this, playerzpot_team.class));
}
}
});
}
public void click(View view) {
Intent intent = new Intent(getApplicationContext(), playerzpot_team.class);
switch (view.getId()) {
case R.id.button3:
intent.putExtra("url", "http://dream11expertteams.com/");
startActivity(intent);
break;
case R.id.button2:
intent.putExtra("url", "https://nikhilsfantasy.wordpress.org");
startActivity(intent);
break;
default:
break;
}
}
}
任何人都可以通过修改代码来帮助我。我想在加载webview之前显示插页式广告。
等待帮助....
答案 0 :(得分:0)
您只需为按钮创建不同的onClickListeners
,然后将网址传递为intent
。你不需要两项活动。只需从活动中的intent
获取网址并转到网页浏览。
Button button1 = (Button) findViewById(R.id.button1);
Button button2 = (Button) findViewById(R.id.button2);
button1.setOnClickListener(new OnClickListener() {
public void onClick(View v) {
Intent intent = new Intent(MainActivity.class, SecondActivity.class); // use the names of your activities
intent.putExtra("url", url1);
startActivity(intent);
}
});
button2.setOnClickListener(new OnClickListener() {
public void onClick(View v) {
Intent intent = new Intent(MainActivity.class, SecondActivity.class); // use the names of your activities
intent.putExtra("url", url2);
startActivity(intent);
}
});
然后在WebActivity中使用
获取字符串String url;
Bundle extras = getIntent().getExtras();
if(extras == null) {
url= null;
} else {
url= extras.getString("url");
}