Stop showing add onBackpressed - android

I am using startApp-SDK . on pressing back button from mainActivity. it shows an add by default. I want to stop showing that add on Backpressed. MainActivity extends from TabActivity and contains three tabs on pressing back from any of them show ads. I have override onBackpressed. in all of them. but still showing those ads.
#Override
public void onBackPressed() {
super.onBackPressed();
}
and also tried some other way around but problem don't solve ..
Thanks in advance..

I have find the solution to my question . May be it help someone else..
whlile declaring StartappAd
StartAppSDK.init(this, "105605040","205467351", false); // true for showing adds.
//NOTE: If you don't wish your application to display ads when pressing the Home button,Back Button simply pass false in the last parameter

Related

How to update a tab layout before switching to another tabs

I'm working on a project that has tab fragments in android. They are A,B,C and D.So the problem comes when I click tab B there is a button called "like" when this button direct to another activity. There we can like or unlike friends. When the back button clicked on that activity the tab B fragment should be updated automatically.
I referred so much in the internet but couldn't find a suitable answer to me.
I'm very new to android so I'm asking for your help thanks..
I use this code onResume
public void onResume()
{ // After a pause OR at startup
super.onResume();
setbList(bLikedList);
getBLiked();
bListAdapter = new bListAdapter(getActivity(), bLikedList);
listView.setAdapter(bListAdapter);
//Refresh your stuff here
}
Did you try SetCurrentItem(int i) for ViewPager on Call of OnResume()

How to show "up" / "back" button in Xamarin.Forms?

I am trying to work out how to show the "up" arrow in Xamarin.Forms without a pushing a page onto the stack. I.E. I just want to perform an action when the back button is pressed. I am completely stuck on this so any help would be appreciated.
I have tried creating a custom renderer which handles a view property called DisplayHomeAsBack. Which in the renderer calls the following:
FormsAppCompatActivity context = ((FormsAppCompatActivity)Forms.Context);
Android.Support.V7.App.ActionBar actionBar = context.SupportActionBar;
if (actionBar != null)
{
actionBar.SetDisplayHomeAsUpEnabled(element.DisplayHomeAsBack);
}
Unfortunately it seems this does absolutely nothing, even though all online tutorials and stackoverflow question for android suggest this method.
The plan is that I can then use the "OnBackButtonPressed" override in MasterDetailPage, which should allow me to perform this action. Unfortunately displaying the back button has been the larger hurdle so far!
Any idea of a better way to do this or how I can get the current mechanism to work?
EDIT
I have created a project and uploaded it to this question on the Xamarin support forums, if it helps.
http://forums.xamarin.com/discussion/comment/186330#Comment_186330
Sorry to keep you waiting so long!
Warning that I did not actually run this code and changed it from my own so I would be surprised if it worked perfectly without some changes.
So below should add a back button where there was not one before (so like when there is not really a page to go back to) and then we will add a custom action to perform when it gets pressed.
I would suggest you push a new page onto the stack without using animation so it is transparent to the user and also makes all of this much simpler, but if you absolutely do not want to do that, the below method should work.
MainActivity:
//Use this to subscribe to the event which will create the back button
public override bool OnCreateOptionsMenu(IMenu menu) {
if(menu != null && App.AppMasterPage != null) { //You will need this to make sure you are on your MasterDetailPage, just store a global reference to it in the App class or where ever
Xamarin.Forms.MessagingCenter.Unsubscribe<string>(this, "CreateBackButton");
Xamarin.Forms.MessagingCenter.Subscribe<string>(this, "CreateBackButton", stringWeWillNotUse => { //Use this to subscribe to the event that creates the back button, then when you want the back button to show you just run Xamarin.Forms.MessagingCenter.Send<string>(this, "CreateBackButton")
ActionBar.DisplayOptions = ActionBarDisplayOptions.ShowTitle | ActionBarDisplayOptions.ShowHome | ActionBarDisplayOptions.UseLogo | ActionBarDisplayOptions.HomeAsUp; //You may need to play with these options to get it working but the important one is 'HomeAsUp' which should add the back button
});
} else {
Xamarin.Forms.MessagingCenter.Unsubscribe<string>(this, "CreateBackButton");
}
return base.OnCreateOptionsMenu(menu);
}
Now the next step is do do a custom action when it is pressed. I think you can either override OnBackPressed() or OnOptionsItemSelected() in MainActivity or maybe you can override the MasterDetailPage method. I am not sure.
Which ever one works for you, inside of that override, I would simply check to see if you are on your App.AppMasterPage like we did above, and if so, send a MessagingCenter message which your App.AppMasterPage has already subscribed to in order for it to handle the custom action.
If you get stuck let me know!
I know it sounds like a bit of a hack, but the best "solution" I have found so far is to add a page behind the current page (behind the root) so it is not visible. Then when the user presses the back button, handle it by removing that page.

How to use setContentView(layout_id) second time in main_activity of android code?

My activity_main.xml has 2 buttons. I have implemented onClickListner(); for both of them .
For MainActivity, - > setContentView(R.layout.activity_main)
This activity_main has the 2 buttons.
Button1 - setContentView(R.layout.layout1);
Button2 - setContentView (R.layout.layout2);
Is this the proper way to use?? Because..
The program runs fine. The problem is that when I click Button2, the layout2 loads, I want to come back to main_activity now, So I press 'Back' button.
The entire app closes..!! I am taken to homescreen of the phone.
How to get around this?? I say ViewSwitcher. I do not have a button to come back.
Any other way?? Please excuse for basic question and bad English.
U have to override onBackPressed() function in your activity and again u have to setContentView to activity_main.xml and remove the super.onBackPressed from onBackPressed.
Something like this:
#Override
public void onBackPressed() {
//validation if you are in second layout
if(layout2){
//do things
showLayout1();
}else{
super.onBackPressed();
}
}
You should pretty much never call setContentView() more than once. What you're describing is standard backstack behavior. Either start a new Activity whatever layout you're transitioning to, or switch to using Fragments, and add a new Fragment to the backstack instead of calling setContentView().
Both approaches will give you native behavioral support for the back button.

How to Handle back button for Fragment in android?

I would like handle back button in my application i have used fragment class in whole application .So when i would like to come back to base activity,it throw out application,Please give me any suggestion.
You just need to override the onBackPressed method on your activity.
#Override
public void onBackPressed() {
//Put your logic here :)
}
I dont understand what you want to do, but if you want to implement your own code in the back button this is how you do it.
#Override
public void onBackPressed() {
// your code
}
If you do nothing, then nothing will happen on a back press.
Edit: perhaps the above is not at all what you want, I've some difficulties understanding you. However, if you properly want to understand activities and how they are managed / created this is a must read. http://developer.android.com/guide/components/tasks-and-back-stack.html

Tab issue in android with back button

I am using tab host(tabs) in application, it have four tabs on home screen, I have set new layouts on every tabs, I want to that once user clicking tabs like: tab1>tab2>tab3>tab4 and press back on tab4 he/she should go back to tab3 and on tab3 pressing back go to tab2 and so on. I didn't get any idea, how to implement? Could any one help me on this, any help will be appreciated. Thanking you all..!!
Create the below method in your class which extends TabActivity,
public void switchTabBar(int tab) {
tabHost.setCurrentTab(tab);
}
And now in your activity's back press method, do this,
public void onBackPressed() {
TabBar parentTab = (TabBar) this.getParent();
parentTab.switchTabBar(1);//Instead of 1 provide the tab position which you want to navigate to.
}
you can override onBackPressed() and inside it do what you want.
I dont know why you want to add back button.In tabs there's no need to add back button.See the below link
http://developer.android.com/resources/tutorials/views/hello-tabwidget.html
You need to create some sort of a activities-backstack (if you use nested ActivityGroup), override onBackPressed() method in your TabActivity and manage this backstack in onBackPressed() method.
You have 2 options:- with Tab or without Tab.
If it is not necessary that you have to use tab in your code then instead of tab you can use buttons and you can easily get your goal. But if you want to use tab then you have to Override onBackPressed() in every 4 Activity.
I hope you got any idea according to my answer. I hope it helps you.

Categories

Resources