这是我的活动,我会添加非页内广告。 我想如果这个活动是onPause超过30秒,onResume我想显示intestial。 因为通过这个活动和另一个,这个应用程序必须打开网址,然后一旦你回到活动(超过30秒),我想添加一个非页内广告。 可以是这样的事吗?如果是,怎么样?
活动
public class EpisodiActivity extends Activity {
AdView adView;
public class ViewModel {
private String url;
private String name;
public ViewModel(String url, String name) {
this.url = url;
this.name = name;
}
public String getUrl() {
return this.url;
}
public void setUrl(String url) {
this.url = url;
}
public String getName() {
return this.name;
}
public void setName(String name) {
this.name = name;
}
public String toString() {
return this.name;
}
}
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
//creazione fullscreen activity
requestWindowFeature(Window.FEATURE_NO_TITLE);
getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,
WindowManager.LayoutParams.FLAG_FULLSCREEN);
setContentView(R.layout.episodi_activity);
// Look up the AdView as a resource and load a request.
AdView adView = (AdView) this.findViewById(R.id.adView);
AdRequest adRequest = new AdRequest.Builder().build();
adView.loadAd(adRequest);
String[] episodi = getIntent().getStringArrayExtra("Product");
String[] urls = getIntent().getStringArrayExtra("urls");
ListView mylist = (ListView) findViewById(R.id.listView1);
// And in this loop we create the ViewModel instances from
// the name and url and add them all to a List
List<ViewModel> models = new ArrayList<ViewModel>();
for (int i = 0; i < episodi.length; i++) {
String name = episodi[i];
String url = "No value";//ok, so bye :Dwait 1 second please you now another code for this
if (i < urls.length) {
url = urls[i];
}
ViewModel model = new ViewModel(url, name);//, url);
models.add(model);
}
// Here we create the ArrayAdapter and assign it to the ListView
// We pass the List of ViewModel instances into the ArrayAdapter
final ArrayAdapter<ViewModel> adapter = new ArrayAdapter<ViewModel>(this, android.R.layout.simple_list_item_1, models);
mylist.setAdapter(adapter);
mylist.setOnItemClickListener(new AdapterView.OnItemClickListener() {
public void onItemClick(AdapterView<?> arg0, View v, int position, long id) {
// Here we get the ViewModel at the given position
ViewModel model = (ViewModel) arg0.getItemAtPosition(position);
// And the url from the ViewModel
String url = model.getUrl();
startActivity(new Intent(Intent.ACTION_VIEW, Uri.parse(url)));
}
});
}
}
答案 0 :(得分:1)
将当前时间保存到onPause中的共享首选项int。在onResume中将当前时间与保存的时间进行比较,如果超过30秒,则会缩短插页式布局。
看起来像这样:
onPause():
super.onPause();
int pauseTime = System.currentTimeMillis();
SharedPreferences sharedPrefs = getSharedPreferences(PREFS, 0);
SharedPreferences.Editor editor = sharedPrefs.edit();
editor.putInt("pauseTime", pauseTime);
editor.commit();
的onResume:
super.onResume();
int currentTime = System.currentTimeMillis();
SharedPreferences sharedPrefs = PreferenceManager.getDefaultSharedPreferences(this);
int pauseTime = sharedPrefs.getInt("pauseTime",0);
int timePassed = currentTime - pauseTime;
if(timePassed >= 30000) {
// Launch your interstitial activity or call a function in this Activity that brings up your interstitial
}