My main activity calls my Surfaceview game, setting a layout with an adview and surfaceview added (initially I did not use a layout at all before I had to ad the banner). however I have not been able to access the main activity from surfaceview to change the layout so it doesn't include the adview once the game starts. i'm forced to have the banner on continually because of this. attempts to kill the ad still leaves a blank banner. does anyone know how to access main activity functions from surfaceview.
I created a removead() function in the main activity to define a new contextview without the adView, but I can't access it.
context, the main activity, is passed to the Surfaceview on creation. I've tried:
context.removead();
this.getContext().removead();
((Activity) this.getContext()).removead();
ViewGroup vg = (ViewGroup)(
this.getParent());
vg.removeView(adView);
I ended up abandoning attempts to control the adAiew directly from surfaceView, instead creating a Handler in the main activity and sending messages to it from the surfaceView the main activity created. The handler then calls VISIBLE or GONE to the adAiew depending on the message sent.
Related
Currently I encounter an issue somehow, the application lost all those artistic UI animation for example, page flipping, alert view popup, action sheet slide up and etc. That means all those UI will show up immediately without any transition animation. It looked very weird.
Firstly, the app will run smoothly until something trigger the issue above, and after that only re-run the app or kill the app will stop the problem.
There is no error message or any clue that I can figure out what could be the reason. Have any one of you guy has encountered similar issue as above? Please share with me how am I able to solve the issue above. Thanks.
Animations may get disabled for the entire app whenever an attempt is made to animate views on a background thread, e.g. by calling one of UIView's animateWithDuration:animations: family of class methods from a background thread. Be sure to update your app's UI only from the main thread.
You can check if code is running on the main thread by testing [NSThread currentThread].isMainThread and you can ensure it runs on the main thread like so:
dispatch_async(dispatch_get_main_queue(), ^(void) {
// Your code
});
Alternatively, ensure that you're not calling [UIView setAnimationsEnabled:NO] anywhere, as that will also disable animations for the entire app.
So, the main Activity will include an AdView and when user switches to another activity, instead of creating a new AdView, I want to get previously created AdView and add it to current activity's layout.
Is this possible? Setting AdView to a variable inside the mainClass which never dies unless application is exited. (So, adView will be assigned to a variable like it is a static variable)
I am asking this because we create AdView with a Context and if I save AdView variable somewhere else, when the context(activity) it was linked to get destroyed, how could i be able to add it to another Activity with a new context?
Perhaps you could do it by creating a Fragment that just contains the AdView and move the Fragment from one Activity to the next.
Remember the AdView is just like any other Android View, it needs to have a Context.
I'm doing an app that uses a TabBarController and each Tab uses its own navigation controller.
The app has dynamic content and I use viewDidDisappear viewDidAppear methods to create or destroy the objects that I need each time I enter or exit into the ViewController.
My problem is when I start to sail very fast and I don't give time to load the Threads that I use for uploading content such as XML peta app or destroy objects when I leave the ViewController.
How I could control the tabs of the navigationbar or tabbarviewcontroller for not respond until the viewcontroller has loaded all contents?
Excuse me if I'm not well expressed. Thanks!
No matter you use synchronous request or asynchronous request, just show an UIAlertView while loading the data. This will both serve as a notification to the user that something is being loaded, and the it will block the interactions with all the other views on the screen.
As others have suggested in comments, I believe that what you want to do is rearrange the order in which things are triggered. Perhaps something like this:
On viewWillAppear:, clear (or disable or whatever is appropriate) your objects that are no longer valid and begin the load-new-content thread. Perhaps display a UIActivityIndicator or similar.
On viewWillDisappear:, tell the load-new-content thread that it can stop, its results are no longer needed. If you put up an activity indicator, take it down.
At the end of the load-new-content thread, take down any activity indicator, update the UI with the new contents and activate.
I don't really see any way around this -- if the UI is not valid until the new content is loaded, then you have to wait for it.
Another solution might be to cache the contents from the previous fetch, and always display those on viewDidLoad. Then, at the end of your new-content-thread, cache the new contents, and update the UI.
i am using a web view and alsousing the drag event to load next or previous page on drag right or left event simultaneously but the web loads the next page after fininshing the curl up animation.
i want to load page data during the animation,
it takes one second to load the new page after animation finishes.
i have checked the loading timing and sequence, web view is loading page and finish loading before starting animation but curlup animation is actually locking the page.
can any one please help me.
You might try to load the next and previous pages on a background thread, so they will be already loaded when the user tries to reach them...
U might want to create an method to get the views (Eg.getView) that takes an NSURL as argument...
and for every swipe you call:
NextView= [self performSelectorInBackground:#selector(getView:) withObject:nextURL];
PrevView= [self performSelectorInBackground:#selector(sgetView:) withObject:prevURL];
Does Android have an equivalent to Cocoa's viewDidLoad and viewDidAppear functions?
If not, then how would I go about performing an action when a View appears? My app is a tabbed application, in which one of the tabs is a list of forum topics. I would like the topic list to be refreshed every time the view appears. Is such a thing possible in Android?
The Activity class has onCreate and onResume methods that are pretty analagous to viewDidLoad and viewDidAppear.
Activity.onResume
EDIT
To add to this, since some have mentioned in the comments that the view tree is not yet fully available during these callbacks, there is the ViewTreeObserver that you can listen to if you need first access to the view hierarchy. Here is a sample of how you can use the ViewTreeObserver to achieve this.
View someView = findViewById(R.id.someView);
final ViewTreeObserver obs = someView.getViewTreeObserver();
obs.addOnPreDrawListener(new OnPreDrawListener() {
public boolean onPreDraw() {
obs.removeOnPreDrawListener(this);
doMyCustomLogic();
return true;
}
});
onResume() is more like viewCouldAppear. :) public void onWindowFocusChanged(boolean) is the closest to viewDidAppear. At this point within the activity lifecycle you may ask the view about its size.
From my limited, nascent understanding of Android, you implement viewDidLoad type functionality in the onCreate method of your Activity:
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.
The equivalent for viewDidAppear is closer to the onResume method:
Called after
onRestoreInstanceState(Bundle),
onRestart(), or onPause(), for your
activity to start interacting with the
user. This is a good place to begin
animations, open exclusive-access
devices (such as the camera), etc.