I am developing an android application and I want close the window of view adds after I click on the adds window using Resume event.I put a rule in resume event but this rule make adds never show. so if there is a way to make the view adds disappears when I return to my application?
this is my code:
#Override
protected void onResume() {
// TODO Auto-generated method stub
if (adView != null) {
adView.destroy();
}
super.onResume();
}
this is the right code:
protected void onResume() {
// TODO Auto-generated method stub
adView.setAdListener(new AdListener() {
#Override
public void onAdOpened() {
// Save app state before going to the ad overlay.
}
#Override
public void onAdClosed() {
adView.setVisibility(View.GONE);
// TODO Auto-generated method stub
super.onAdClosed();
}
});
super.onResume();
}
use following to disappear the view.
adView.setVisibility(View.GONE):
set an onClickListener on adView then in onClick call this method.
Related
I know there are several answers to this question, but it isn't working for me, currently my code is:
public class LogoutService extends Service {
public static CountDownTimer timer;
#Override
public void onCreate(){
// TODO Auto-generated method stub
super.onCreate();
timer = new CountDownTimer(1 * 60 * 1000, 1000) {
public void onTick(long millisUntilFinished) {
//Some code
Log.v(TAG, "Service Started");
}
public void onFinish() {
Log.v(TAG, "Call Logout by Service");
// Code for Logout
stopSelf();
}
};
}
#Override
public IBinder onBind(Intent intent) {
// TODO Auto-generated method stub
return null;
}
}
and in every activity I have:
#Override
protected void onResume() {
// TODO Auto-generated method stub
super.onResume();
LogoutService.timer.start();
}
#Override
protected void onStop() {
// TODO Auto-generated method stub
super.onStop();
LogoutService.timer.cancel();
}
But I get a "Unable to resume activity java.lang.NullPointerException: Attempt to invoke virtual method 'android.os.CountDownTimer android.os.CountDownTimer.start()' on a null object reference" when I try to start any of my activities that contain this code. My application isn't too complicated, it's completely offline, so no web service calls or anything, I just need to go back to my login activity after x minutes. Anyone have any ideas?
Here's the one I used: Auto logout after X minutes, Android and http://androidjug.blogspot.com/2015/10/auto-logout-after-15-minutes-due-to.html
You aren't starting the service, so you aren't allocating the timer. Really you should not be using a static for this.
i always error
this my activity
public class ARActivity extends SherlockFragmentActivity {
ArchitectView arview;
#Override
protected void onCreate(Bundle arg0) {
// TODO Auto-generated method stub
super.onCreate(arg0);
setContentView(R.layout.sample_cam);
this.arview = (ArchitectView) findViewById(R.id.architectView);
final ArchitectConfig config = new ArchitectConfig(
WikitudeSDKConstants.WIKITUDE_SDK_KEY);
this.arview.onCreate(config);
}
#Override
protected void onPostCreate(Bundle savedInstanceState) {
// TODO Auto-generated method stub
super.onPostCreate(savedInstanceState);
this.arview.onPostCreate();
try {
this.arview.load("assets/wikitude/imageRecognition/index.html");
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
}
and this my xml
and i get error
please help me :(
Please check out the Wiktiude SDK Sample App, which is part of the Wikitude SDK.
It comes with a "AbstractArchitectCamFragmentV4.java" and a "AbstractArchitectCamActivity.java", which define the required lifecycle methods properly.
I guess implementing the remaining onResume, onPause, onDestroy should solve the issue.
Kind regards,
Andreas
How can I write command in onclicklistener() so that I can move to next activity as well as my post status dialog will appear on that new activity. I am using intent for switching to next activity and also using postTowall() method. But these two doesn't perform simultaneously. I am using this method:
public void onClick(View v) {
// TODO Auto-generated method stub
postTowall();
Intent intent= new Intent(Frnd.this,Logout.class);
startActivity(intent);
}
private void postTowall() {
facebook.dialog(this, "feed", new DialogListener() {
#Override
public void onFacebookError(FacebookError e) {
}
#Override
public void onError(DialogError e) {
}
public void onComplete(Bundle values) {
String sh = null;
Bundle params = new Bundle();
params.putString("caption", sh);
}
public void onCancel() {
// TODO Auto-generated method stub
}
You can use thread for posting. Use asynctask and inside that post the message to face book. Or you may just write a simple thread and start it.
This asynctask link may help you. it has usage example also:
http://developer.android.com/reference/android/os/AsyncTask.html
You should set other activity to open post dialog. Send via intent a signal if it should or not...
I get this error whenever I try to start my window class. I am using separate class, and not just a method within my game class, cause I need to disable back button on that popup window. I am calling this class with a button. This code works fine if I use it within my game class, but not in separate class. Here is my code:
public class Popup_pogresno extends Activity implements OnClickListener{
private PopupWindow pwindow;
#Override
protected void onCreate(Bundle savedInstanceState) {
// TODO Auto-generated method stub
super.onCreate(savedInstanceState);
LayoutInflater layoutInflater
= (LayoutInflater)Popup_pogresno.this
.getSystemService(LAYOUT_INFLATER_SERVICE);
View popupView = layoutInflater.inflate(R.layout.popup, null);
pwindow = new PopupWindow(popupView, 300, 170, true);
Button btnDismiss = (Button)popupView.findViewById(R.id.bPopupOK);
btnDismiss.setOnClickListener(new Button.OnClickListener(){
public void onClick(View v) {
// TODO Auto-generated method stub
pwindow.dismiss();
}});
pwindow.showAtLocation(popupView, Gravity.CENTER, 0, 0);
}
public void onClick(View v) {
// TODO Auto-generated method stub
}
#Override
public void onBackPressed() {
}
}
You are not calling setContentView(R.layout.myLayout) in your onCreate(Bundle) method. Call it right after super.onCreate(savedInstanceState);.
This is from the Activity resource page on Android developers site:
There are two methods almost all subclasses of Activity will
implement:
onCreate(Bundle) is where you initialize your activity. Most importantly, here you will usually call setContentView(int) with a
layout resource defining your UI, and using findViewById(int) to
retrieve the widgets in that UI that you need to interact with
programmatically.
onPause() is where you deal with the user leaving your activity. Most importantly, any changes made by the user should at this point be
committed (usually to the ContentProvider holding the data).
Edit 1:
Replace:
pwindow.showAtLocation(popupView, Gravity.CENTER, 0, 0);
with:
new Handler().postDelayed(new Runnable(){
public void run() {
pwindow.showAtLocation(popupView, Gravity.CENTER, 0, 0);
}
}, 100L);
I am new to android programming. So, I am trying to download a file from internet in async task and showing progress dialog until download finished. But if i switch my applications in between, say I open another app, progress dialog disappears.
This is the code I am using to show progress dialog
progressDialog.setIndeterminate(false);
progressDialog.setCancelable(false);
progressDialog.setMessage("Backing Up...");
progressDialog.setMax(100);
progressDialog.setProgressStyle(ProgressDialog.STYLE_HORIZONTAL);
progressDialog.show();
What am i doing wrong here?
First If you are using the asynctask it runs on UI Thread so you must be switching from the home button it puts your app on the pause you can override onPause and onResume methods
I solved it by adding these methods in my code.
#Override
public void onDestroyView()
{
if (progressDialog != null && getRetainInstance())
progressDialog.setDismissMessage(null);
super.onDestroyView();
}
#Override
public void onSaveInstanceState(Bundle outState) {
// TODO Auto-generated method stub
super.onSaveInstanceState(outState);
}
#Override
public void onCreate(Bundle savedInstanceState) {
// TODO Auto-generated method stub
super.onCreate(savedInstanceState);
setRetainInstance(true);
}