Trying to understand when viewWillAppear is called in simple app...

This test application contains one button and one label. It was created with XCode 3.2.4 for the iPhone. I created it using the View-based application template in XCode.
When the application launches, the label displays "Clear when Home Button is pressed". This string is located inside of - (void) viewWillAppear:(BOOL)animated. Then when the button is pressed, the text inside of the label changes to "Label text should change when the application quits.".
The problem is when I press the Home Button to close the application, and then relaunch it, "Clear when Home Button is pressed" should be automatically displayed. Below is the code:
//removeLabelWhenClosedViewController.h
#import <UIKit/UIKit.h>
@interface removeLabelWhenClosedViewController : UIViewController {
IBOutlet UILabel *removeTextWhenClosed;
@property (nonatomic, retain) IBOutlet UILabel *removeTextWhenClosed;
- (IBAction)pressButton: (id)sender;
@end
//removeLabelWhenClosedViewController.m
#import "removeLabelWhenClosedViewController.h"
@implementation removeLabelWhenClosedViewController
@synthesize removeTextWhenClosed;
- (IBAction)pressButton: (id)sender
NSString *displayLabel = [[NSString alloc] initWithFormat:@"Should go away with application quits."];
removeTextWhenClosed.text = displayLabel;
[displayLabel release];
- (void) viewWillAppear:(BOOL)animated
NSString *clearLabel = [[NSString alloc] initWithFormat:@"Clear when Home Button is pressed"];
removeTextWhenClosed.text= clearLabel;
//playNumber.text = @"";
//NSLog(@"viewWillDisappear");
[clearLabel release];
- (void)dealloc {
[super dealloc];
@end

T2TU wrote:
The problem is when I press the Home Button to close the application, and then relaunch it, "Clear when Home Button is pressed" should be automatically displayed.
Are you sure you're actually relaunching the app? By default, when your app is in the foreground on iOS 4, pressing the home button will place the app in the background. I.e. the app will either be suspended or continue running in the background, but it won't exit. When you subsequently tap its icon, the app will move to the foreground, but the currently "visible" view won't get a viewWillAppear: message.
I think the easiest fix would be to send viewWillAppear to the active (and in your case, only) view controller from [applicationWillEnterForeground:|http://developer.apple.com/library/ios/documen tation/UIKit/Reference/UIApplicationDelegateProtocol/Reference/Reference.html#//appleref/doc/uid/TP40006786-CH3-SW21]:
// MyAppDelegate.m
- (void)applicationWillEnterForeground:(UIApplication *)application {
[viewController viewWillAppear:NO];
- Ray
p.s.: As usual, xnav replied while I was in the editor Just to clarify the difference between our advice, I think x is suggesting you ensure the app actually terminates when the home button is pressed--another approach which will solve your problem. - R
Message was edited by: RayNewbie

Similar Messages

  • When receiving phone calls, the background apps play through the speaker making it impossible to hear the person on the other line. How do i fix this? This started happening on my iphone 4 and now i have the same problem with my iphone 4s.

    I once had a phone call in the middle of a trip. I was listening to my music and phone rang. It was work calling. I answered the phone and the music continued to play. I had to tell the person to hold, then i had to use multitask to find the app and manually turn it off. Once that was done, i retrurned to the phone call to find out that when i receive an email it too plays through the speaker while i am on the phone. Why wouldn't it mute these things while i am making a phone call? Is there a setting for this? It seems to me that this only happened since IOS 5, but i can't be 100%. What i am 100% on is the fact that it happened on my Iphone 4 and is now happening on my Iphone 4s.

    The music continued to play with the iPod?
    If so, when a call is received while listening to music with the iPod, when the call is answered the music should be paused. When ending the call, the music starts playing again from where is was paused.
    There is no automatic mute with notifications for received email or messages while on a call and there is no setting for this.

  • My IPod apps won't open. So I looked it up, and it said to sync the apps to itunes, i tried this, but when i try to sync, the apps won't show up on Itunes. It keeps saying "0 apps". What do i do?

    Ever since yesterday, my Ipod apps won't open properly. I googled it, and couldn't find anything accurate. So i deleted all of the apps, and re-downloaded them. Now they're doing it again. When i tap on it, it looks like it wants to open, but then it goes back to the main menu. I googled it again, and got an answer saying to go to Itunes, uncheck the "sync apps" box, and sync. Then after that, recheck the box, and sync again. Many people said this worked, but it didn't for me. Also whenI go to sync my apps, they don't show up in Itunes. How do I get them to show up in Itunes?

    I had the same issue. After searching around online I found out that you can try downloading another app (it can be any app) onto your ipod. After it finishes downloading see if your other apps open. You don't even have to keep the new app. Just see if your other ones work and you can delete the new one. That should work. If not, try to hard reset it. Here is another apple support link for steps on hard reseting it (http://support.apple.com/kb/HT1430). 

  • My phone doesn't ring when someone is calling, but the sound works otherwise, like the alarm etc. I have tried to fix it in settings but still not working. anyone else have this problem?

    my phone doesn't ring when someone is calling, but the sound works otherwise, like the alarm etc. I have tried to fix it in settings but still not working. anyone else have this problem?

    Thanks so much but none of that helped.  It was driving me crazy because it would back up another external drive.  I just changed the name of the drive from iPhoto/iTunes Library to Media Libraries and IT WORKED!! I guess for some reason it didn't like the drive being called iPhoto or iTunes ???? I don't understand but I have tried so many solutions and exchanging things out but the name change did it????!!!
    Thank you for your help and replying to this.  Guess I made my own issue!

  • I don't understand the thing you call live bookmarks never used it, and most forums I have used notify VIA E-mail not giving out my E-mail address information when a reply has been made to the thread in question.

    So how do I get notified of updates in this forum? As I said: I don't understand the thing you call LIVE BOOKMARKS I have never used them, and most forums I have used notify VIA E-mail not giving out my E-mail address, or other private information when a reply has been made to the thread in question, so how do I get notified of updates in this forum? I have seen no normal options for setting my viewing preferences used for this forum. Thank You.

    Thanks for your reply via email/msg. He wrote:
    If you are interested in the actual design data for the Xeon processor, go to the Intel site and the actual CPU part numbers are:
    Xeon 4 core - E5.1620v2
    Xeon 6 core - E5.1650v2
    Xeon 8 core - E5.1680v2
    Xeon 12 core - E5.2697v2
    I read that the CPU is easy to swap out but am sure something goes wrong at a certain point - even if solderedon they make material to absorb the solder, making your work area VERY clean.
    My Question now is this, get an 8 core, then replace with 2 3.7 QUAD CHIPS, what would happen?
    I also noticed that the 8 core Mac Pro is 3.0 when in fact they do have a 3.4 8 core chip, so 2 =16? Or if correct, wouldn't you be able to replace a QUAD CHIP WITH THAT?  I;M SURE THEY ARE UO TO SOMETHING AS 1) WE HAVE SEEN NO AUDIO FPU OR PERHAPS I SHOULD CHECK OUT PC MAKERS WINDOWS machines for Sisoft Sandra "B-E-N-C-H-M-A-R-K-S" -
    SOMETHINGS UP AND AM SURE WE'LL ALL BE PLEASED, AS the mac pro      was announced Last year, barely made the December mark, then pushed to January, then February and now April.
    Would rather wait and have it done correct than released to early only to have it benchmarked in audio and found to be slower in a few areas- - - the logical part of my brain is wondering what else I would have to swap out as I am sure it would run, and fine for a while, then, poof....
    PEACE===AM SURE APPLE WILL BLOW US AWAY - they have to figure out how to increase the power for 150 watts or make the GPU work which in regard to FPU, I thought was NVIDIA?

  • Trying to understand problems that occur when redistributing between two OSPF processes

    Hi all, I'm currently brushing up on my OSPF and trying to understand the problems that can occur when redistributing between two OSPF processes. I have read and understand (I think!) the issues caused by the fact that the same route submitted by two different OSPF processes may not necessarily follow the OSPF rules that one would expect - for example, OSPF preferring intra-area routes to inter-area routes to external routes, but only within the same process. So, if the same route is submitted from two different processes, that rule goes out the window.
    But I'm having some difficulty getting my head around the idea of setting the administrative distance lower in one OSPF process to prefer one domain over the other. I just can't quite follow the example described in this document:
    http://www.cisco.com/c/en/us/support/docs/ip/open-shortest-path-first-ospf/4170-ospfprocesses.html#twored
    Specifically, in figure 4 where two external networks - external network "N" originating in OSPF domain 1, and external network "M" originating in OSPF domain 2 - are redistributed via two ASBRs. The explanation states:
    This sequence of events could occur occur:
    Router A (Router B) redistributes M into Domain 1, and external M will reach Router B (Router A).
    Because the administrative distance of Domain 1 is lower than Domain 2, Router A (Router B) will install M through Domain 1 and will set to maxage its previous originated LSA (event 1) into Domain 1.
    Because M has been set to maxage in Domain 2, Router A (Router B) will install M though Domain 2 and, therefore, will redistribute M into Domain 2.
    Same as event 1.
    I can't quite work my way through this. I guess it must have something to do with the redistribution of "M" from domain 2 into domain 1 being learned by both ASBRs due to the lower administrative distance assigned to external routes in domain 1, and the original routes through domain 2 being deleted, but then I can't follow the rest of the description. And I can't understand why this would be a problem for network "M" in OSPF domain 2, but NOT for network "N" in OSPF domain 1.
    Any explanation gratefully received!
    Thanks, Graham

    Hello.
    You are right - whenever A and B learns about "M" from Domain 2, they craft LSA for domain 1 and inject it simultaneously. They learn each other's LSAs simultaneously and withdraw (set timer to 3600) for previous LSAs. And it might flap infinitely.
    If they don't learn LSA simultaneously (let's say that A is much faster then B), then there will be no flaps, but B would learn all Domain 2 routes (not just redistributed) via Domain 1.
    And later you will observe routing loop (when you stop advertising M from D): A knows "M" from Domain 2 and injects into Domain 1, B knows from A via Domain 1 and injects into Domain 2... so "M" stays in the routing tables due to mutual redistribution.
    You don't have similar (flap) issue with network "N", because admin distance is lower for Domain 1, so both routers would never prefer OSPF via Domain 2! But having no issue with route flaps, you still will observe routing loop if you stop advertising "N" from C.

  • There were no results for I've downloaded the kindle app to my new iPad4 but when I went to Amazon UK and tried to download a book it said "this mobile app does not currently support digital downloads. I don't understand! I'm in the UK.

    There were no results for I've downloaded the kindle app to my new iPad4 but when I went to Amazon UK and tried to download a book it said "this mobile app does not currently support digital downloads. I don't understand! I was told you could download kindle books from amazon straight to iPad if you download the kindle app first. Do I have to do it onto my computer and then sync it onto iPad? surely not?

    Can you go here:
    http://www.amazon.co.uk/Kindle-eBooks/b/ref=amb_link_173148087_8?ie=UTF8&nav_sdd =aps&node=341689031&pf_rd_m=A3P5ROKL5A1OLE&pf_rd_s=center-1&pf_rd_r=1GDPPW8ZCN9Y 9NQF5VV0&pf_rd_t=101&pf_rd_p=365751407&pf_rd_i=468294
    and not log on. See what you can do.

  • HT201401 my iPhone 5 randomly switched itself when somebody was calling me and now won't turn on. it had 90% battery, I've tried factory reset, connecting to iTunes and nothing works. the phone is approx 18 months old so surprise surprise out of warranty.

    my iPhone 5 randomly switched itself when somebody was calling me and now won't turn on. it had 90% battery, I've tried factory reset, connecting to iTunes and nothing works. the phone is approx 18 months old so surprise surprise out of warranty.

    My 5S just started doing this on Thursday: every fraction of a second or so it oscillates between connecting and disconnecting with the charger (USB or wall, doesn't matter). Since it's still under the limited warrantee, I took it to the local Mac dealer (I live in a small town w/out an Apple store) and they shipped it off. I'm waiting now for the replacement--telephonless, too!
    What concerns me is that many people seem to be having this issue.
    You were right to be suspicious of the Apple store employees. Once they replicated the behavior that you experienced, they should have immediatly offered to exchange your phone. Anything else, in my opinion, is unacceptable. As long as your phone is still doing it, I'd go back, ask for the manager and tell them to exchange your phone.

  • Trying to understand Android OS updates delays

    This is not another hate mail, it´s more about trying to understand the facts and motives regarding the OS updates (or lack of).
    Hopefully this material will arrive at someone from Sony with enough power to do something about it.
    Ever since I can remember, Sony has been THE brand for electronics. I can´t remember a TV or VCR in my house that it wasn´t Sony, and they lasted for LOTS of years.
    When a couple years ago I finally had the money (and the need) for a Smartphone, i chose the X10 Mini, which is a great little phone from a great brand, but it´s stuck at Android 2.1... which makes it a crippled android nowadays...
    It really bothered me the lack of OS updates, so I chose to buy a Galaxy Nexus, but it´s really expensive in my country. So my second option was a Galaxy Ace 2, but they haven´t arrived to my country yet, so I went with my third option: Xperia Sola, knowing beforehand that it´s a great phone, a great brand, but I might get slow OS updates.
    I bought it about 10 days ago when I saw they were starting to roll out the updates.
    10 days later I still don´t have my update. And not only that, but I don´t see much light at the end of the tunnel...
    I found a thread with the SI numbers that were updated, and there were a bunch on Oct 1, another bunch on Oct 4, and one code on Oct 8, and no other update since...
    I also read that those who did get the update, were having bugs with the OS, and also found threads from other Xperia models, whose updates began rolling 3 months ago, and there is still people who hasn´t gotten the update...
    As a customer, and a owner/CEO of a small company, I have a really hard time understanding how a HUGE company like Sony can be making such mistakes...
    I have been thinking objective reasons, and I can only think of one. I know it´s a wild guess, but I´m starting to think that our salvation might be the very thing that means our condemnation: CYANOGENMOD!!!
    Think about it: Why would Sony spend more money hiring twice as much programmers, when they can make only one update per phone, and sit down and see how CM releases begin to appear, for all tastes and needs. And... IT´s FREE!!!
    Also, if there is a software related problem (way more likely than a hardware problem), then the CM developers take the fall, instead of Sony. And I´m beginning to see custom OS installers that are more user friendly, so it might be something that they take in accout when neglecting OS updates.
    If that´s the line Sony is following, it´s a very risky move and it won´t work. Sony Mobile will crash and burn, but it´s still a better business plan that "let´s get lazy and make ULTRA slow updates so we don´t spend a lot of money programming".
    If you can´t afford more programmers, stop including so much bells and whistles and make your OS near vanilla. Include a couple of Xperia menus, a custom theme and voila!
    The main reason I wanted the Galaxy Nexus is Vanilla OS, which means inmediate OS updates. Sony on the other hand, takes a year or two to release it after its launch. If they release it at all...
    Another though...  why not stop making that many different phones! Really! There are like 5 Xperia models i can´t tell one from the other... even with specs side by side!
    You are trying to make too many phones and you are failing with all of them! (Software and software updates are also part of the phone, one of the most importants...)
    I know hiring programmers is expensive, but you are sacrificing one of the most expensive values for a company EVER: Customer credibility! Which as you know better than me, takes years to create.
    If Apple had problems with carriers and code aprooving and stuff, they might get away with it, becouse they alone have all the devices. If iOS 6 is delayed a few months, it´s delayed for everyone, and besides Apple fanboys rarely complain about Mac products, but Android is a more independent and educated market.
    I´m not saying that Apple users are ignorant, not at all, but I´m pretty sure most iPhone owners don´t even know what processor or how much RAM their phone has. They just "swallow" the Apple Way of Life. (it´s a good phone becouse Apple says so).
    The Android user on the other side, because of the fragmentation of the market, has many brands and models to choose from. An Android user about to buy a new phone will most likely go online looking for different models, specs, reviews in webs and forums...etc.
    You can´t say "I don´t know how HTC and other companies get their updates so soon, but we take a lot more becouse Google and the Operators must aproove the code.", because there are many other brands that have exactly the same difficulties or more, since they are smaller, and we can SEE online that they are indeed delivering solid and relativly fast updates.
    Did we miss something? Does HTC use Witchcraft to get their code aprooved?
    My underlying point is this: You are getting lazy... VERY lazy with software programming for your phones, and WE KNOW IT!
    It´s not the "difficulties" you claim, becouse every brand has those difficulties.
    This isn´t 1999 you know. We are in the information age. If you lie to us and tell us that your phones have the latest OS, I can go online and see that you don´t (Hello!!!). If I see that the company lies to it´s customers, I will stop buying their products. If I´m so dissapointed with how Sony handles OS updates and their customers queries about it, then I want for the first time ever to sell my Cell Phone becouse I´m not happy with it, or the brand behind it.
    We also live in the "Here and now" age. You can´t expect your customers to read about new Android releases on news and blogs, and wait YEARS with arms crossed waiting for their update... The world doesn´t work like that. Not anymore at least...
    It´s not a matter of how many recources you have, it´s about how you use and balance them. GIVE MORE IMPORTANCE TO SOFTWARE UPDATES! IT´S WAY MORE IMPORTANT THAT YOU THINK! LISTEN TO YOUR CUSTOMERS!!!
    You guys are Sony are smart and design great products, but you are not GOD! You are not our wife, no one has sworn alliagence to you.
    If you stop giving us good products and start lying to us, we hate you and stop giving you our money. Simple as that.
    My sola is beatiful, I love the design, the screen, the hardware... but it hasn´t been updated yet to 4.0, not to mention 4.1, which REALLY is the latest version... so stop advertising that your phones have the latest Android OS, unless you want angry customers switching to other companies, which you are getting.
    I also read some stories that Androind 4.0 was announced for the Xperia PLAY, and then it was called off... Do you have any idea how pissed I would be and ripped off I would be if I bought my phone based in that information and then you say it won´t be available?
    Well, actually right now my possition is worse, since you SAY you will update my phone, but you don´t say when, and I read online about people still not getting their updates months after the rollout started, so I´m in the limbo right now...
    As a company, one of the worse things you can do is calling your customers stupid, and when I see the answers you give in this forum, then I feel insulted. I feel like they are talking to an idiot or ignorant person with the so called "diplomatic" answers, which are basicly empty excuses for not doing your job right.
    You gave us the frikking CDs, DVDs and Blu-Rays!!! Don´t tell us you can´t tweak an already built OS in a year!
    I really hope you change their OS update policies really soon, before you lose the already small cellphone market share you have, or at least change your P.R. and C.M. policies towards a more open one.
    We all are humans and make mistakes, but we customers really appreciate honesty and truth.
    Have an open conversation with your customers! Don´t lie about your shortcomings! Accept then and ask the community to help you solve them, ask them what they biggest problems are, what features are most important to them, how often do they expect updates... LISTEN TO THEM!!
    "Succes is a meneace. It tricks smart people into thinking they can´t lose."
    Ps: Nothing personal with the mods from this forum, I´m not killing the messenger, I know that you can ONLY give the info you are allowed to give, and even if you wanted, you probably don´t know the answers yourself, since you work in the Communications department, not Developement or anything technical, and if you can't give any given info, then they probably won´t give it to you either... My message is to the company as a whole. I just hope you will be a good messenger and give this to whoever needs to read it.

    My bad, it´s closer to 40 the number of phones released hehe
    I know it´s all about money, and I know Sony is obligated to neglect users who haven´t given them money after an x ammount of time. However, it´s not a matter of making the phones obsolete earlier, so the users want to buy a new phone faster and therefore getting more money.
    A person will buy a new phone when he/she has the money to do so and wants to do so.
    It´s not a matter of WHEN. It´s a matter of WHAT.
    The question is not "When will that user buy a new phone?", but rather "When that user buys a new phone, whenever that is, what phone will it be?"
    I have a love/hate relationship with Apple. I would never use a iPhone. I would love having any Mac, if someone gives it to me, but I would never spend my harn earned dollars on such an overpriced piece of hardware over general principals.
    However, i do recognice that Steve Jobs was a business genius. Weather you like or love his ideas and methods, he turned a garage project into the biggest company in the world, with a market value higher than Exxon with 1/3 of it´s assets.
    Apple is a money making machine, and that is where the "hate" part of my relationship comes from.
    However, it surprised me a lot to see that they released iOS 6 for the iPhone 3GS, released in 2008!
    That get´s you thinking, that inside all that "SELL NOW" culture Apple is, they also support their older devices that people bought years ago but can't buy a new phone now. However, when they can do it, it will surely be another iPhone. Because they FEEL that the company listens and cares for them.
    Also if you jump from iOS 6 on the 3 GS to a brand new iPhone 5, the transition will be virtually non-existant, except for Siri and a couple of features.
    However jumping from Android 1.5 or 2.1 to Jelly Bean, might not be so easy on some users, making them more likely to give iPhone a shot.
    Since they have to adapt to another phone anyway, they might as well try the apple...
    And for old users, it gives people a sense of continuity and care about the user. Otherwise we feel like being kicked out of a restaurant right after we payed the bill.

  • Trying to understand the basic concept of object oriented programming.

    I am trying to understand the basic concept of object oriented programming.
    Object - a region of storage that define is defined by both state/behavior.
    ( An object is the actual thing that behavior affects.)
    State - Represented by a set of variables and the values they contain.
    (Is the location or movement or action that is the goal that the behavior is trying to accomplish.)
    Variables- (What does this mean?)
    Value - (What does this mean?)
    Behavior - Represented by a set of methods and the logic they implement.
    ( A set of methods that is built up to tell's the how object to change it's state. )
    Methods - A procedure that is executed when an object receives a message.
    ( A very basic comand.For example the method tells the object to move up, another method tells the method to go left. Thus making the object move up/left that combination is the behavior.)
    Class - A template from which the objects are created.
    ( I am very confused on what classes are.)
    - The definitions of the words I obtained from the "Osborne Teach Yourself Java". The () statements are how I interperate the Mechanisms (I do not know if Thats what you call them.) interact with each other. I understand my interpretation may be horribly wrong. I will incredibly appreciate all the support I may get from you.
    Thank you

    Object oriented programming is a replacement for the older idea of procedural programming (you can research procedural programming in google). As I understand it, in procedural programming, you have a step by step set of function calls to accomplish some task. Each function receives a data structure, manipulates it, and passes it to the next function. The problem with this is that each function preforms some action for the overall task and can't easily be reused by some other task. Its also harder to read the flow of what is happening with raw data structures flying all over the place.
    In object oriented programming, an object calls a function of another object and receives back, not a data structure, but another object. Objects contain a data structure that can only be accessed by its functions. An object is not so much a sub component of a bigger task, as it is a service that any other task can use for any purpose. Also, when you pass an object to the caller, the caller can ask questions about the data structure via its functions. The developer doesnt have to know what the previous function did to the data by reading up on any documentation, or having to reverse engineer the code.
    I suggest the best way of learning this is to code something like a library object.
    A library object contains a collection of book objects
    A book object contains a collection of chapter objects
    A chapter object contains a collection of paragraph objects
    A paragraph object contains a collection of sentence objects
    A sentence object contains a collection of word objects.
    Add functions to each object to provide a service
    Example: A library object should have a:
    public void addBook(Book book)
    public Book getBook(String title)
    public boolean isBookInLibrary(String title)
    The key is to add functions to provide a service to anyone who uses your object(s)
    For example, what functions (service) should a paragraph object provide?
    It shouldn't provide a function that tells how many words there are in a sentence. That function belongs to a sentence object.
    Lets say you want to add a new chapter to a book. The task is easy to read
    if you write your objects well:
    Sentence sentence1=new Sentence("It was a dark and stormy night");
    Sentence sentence2=new Sentence("Suddenly, a shot ran out");
    Paragraph paragraph=new Paragraph();
    paragraph.addSentence(sentence1);
    paragraph.addSentence(sentence2);
    Paragraphs paragraphs=new Paragraphs();
    paragraphs.addParagraph(paragraph);
    Library library= new Library();
    library.getBook("My Novel").addChapter("Chapter 1",paragraphs).
    Now, lets say you want to have a word count for the entire book.
    The book should ask each chapter how many words it contains.
    Each chapter should ask its paragraphs, each paragraph should ask
    its sentences. The total of words should ripple up and be tallied at each
    stage until it reaches the book. The book can then report the total.
    Only the sentence object actually counts words. The other objects just tallies the counts.
    Now, where would you assign a librarian? What object(s) and functions would you provide?
    If written well, the project is easily extensible.

  • Trying to understand hashCode( )

    Hello again, I'm trying to understand the hashCode( ) method. I have a textbook which describes it this way:
    "A hashcode is a value that uniquely identifies an individual object. For example, you could use the memory address of an object as it's hashcode if you wanted. It's used as a key in the standard java.util.Hashtable[i] class."
    Please forgive me if this emplies that I may be a bit slow with this, but this explanation is too vague for me to grasph what's going on here. Can someone thoroughly explain (in a non scientific way), how and why this method is used?
    Thanks in advance.

    I thought the examples I provided might give you an idea why the hashCode method is useful. I'll try one more brief one, and if that doesn't connect that spare wire to the light bulb over your head, then I'll have to agree with schapel and suggest that you study up on your CS theory.
    This will be a really crocked up example, and you could skirt some of the issues with better design, but it's a valid example nonetheless.
    You run a greenhouse or an arboretum or something. You've got 25,000 Tree objects (forget their subclasses for now). Trees have properties like species, name (I don't know why you'd name a tree--just bear with me), location, age, medical history. You're going to put your Trees into a java.util.Set, so you've got a collection with one reference to each tree. However, you're getting overlapping subsets of your trees from various sources--that is getAllElms() returns some trees that are also in getAllOlderThan(10). You need to combine all those results into a 1-each collection of Trees.
    When you go to add an Object to the Set, the Set has to first check if that Object is already present. The Set implementation could iterate over all its elements and call equals() to see if that Object is already there. Or, it could first get the hashCode (let's say you've implemented hashCode to return the xor of the species and the age). So, maybe 100 out of your 25,000 trees are 50 yeard old Elms. Internally, if the Set implementation keeps a mapping from hashCode to an array of Trees with that hashcode, then it only has to copmare to those 100 trees that match, rather than all 25,000.
    As I said, this is a cheezy example. One problem is that if trees are mutable, this Set implementation won't work, since the Set won't know that a Tree's internal values (and hence, possibly, its hashCode) have changed.
    Is is making any sense yet?
    Okay so please help me understand this rudimentary,
    logical reason for wanting to use a hashCode( )? Say
    I create a top level class called "Plant.java". Now
    from that class I create a subclass called Tree.java
    from which several other subclasses and objects are
    created. Help me gain a basic understanding of why
    and how the hashCode( ) method might be beneficial.
    (lol... I feel sort of like I've opened up a cool new
    electronic toy, I'm standing here with a "spare wire
    in my hand wondering what the heck this part is
    for?")
    Thanks again for your help. I really apprecitate it.

  • Trying to understand BtrFS snapshot feature

    I'm trying to understand how the copy-on-write and Btrfs snapshot works.
    Following simple test:
    <pre>
    # cd /
    # touch testfile
    # ls --full-time testfile
    -rw-r--r-- 1 root root 0 2012-10-15 12:04:43.629620401 +0200 testfile
    Test 1:
    # btrfs subvol snapshot / /snap1
    # touch testfile
    # ls --full-time testfile /snap1/testfile
    -rw-r--r-- 1 root root 0 2012-10-15 12:04:43.629620401 +0200 /snap1/testfile
    -rw-r--r-- 1 root root 0 2012-10-15 12:07:38.348932127 +0200 testfile
    Test 2::
    # btrfs subvol snapshot / /snap2
    # touch testfile
    # ls --full-time testfile /snap1/testfile /snap2/testfile
    -rw-r--r-- 1 root root 0 2012-10-15 12:04:43.629620401 +0200 /snap1/testfile
    -rw-r--r-- 1 root root 0 2012-10-15 12:07:38.348932127 +0200 /snap2/testfile
    -rw-r--r-- 1 root root 0 2012-10-15 12:09:21.769606369 +0200 testfile
    </pre>
    According to the above tests I'm concluding/questioning the following:
    1) Btrfs determines which snapshot maintains a logical copy and physically copies the file to the appropriate snapshot before it is modified.
    a) Does it copy the complete file or work on the block level?
    b) What happens if the file is very large, e.g. 100 GB and there is not enough space on disk to copy the file to the snapshot directory?
    c) Doesn't it have a huge negative impact on performance when a file needs to be copied before it can be altered?

    Hi, thanks for the answers!
    I guess calling it "logical copy" was a bad choice. Would calling the initial snapshot a "hard link of a file system" be more appropriate?
    Ok, so BTRFS works on the block level. I've done some tests and can confirm what you said (see below)
    I find it interesting that although the snapshot maintains the "hard link" to the original copy - I guess "before block image" (?) - there really is no negative performance impact.
    How does this work? Perhaps it is not overwriting the existing file, but rather creating a new file? So the snapshot still has the "hard link" to the original file, hence nothing changed for the snapshot? Simply a new file was created, and that's showing in the current file system?
    It actually reminds me of the old VMS ODS filesystem, which used file versioning by adding a simicolon, e.g. text.txt;1. When modifying the file the result would be text.txt;2 and so on. When listing or using the file without versions, it would simply show and use the last version. You could purge old version if necessary. The file system was actually structured by records (RMS), similar like a database.
    <pre>
    [root@vm004 /]# # df -h /
    Filesystem Size Used Avail Use% Mounted on
    /dev/sda3 16G 2.3G 12G 17% /
    # time dd if=/dev/zero of=/testfile bs=8k count=1M
    1048576+0 records in
    1048576+0 records out
    8589934592 bytes (8.6 GB) copied, 45.3253 s, 190 MB/s
    Let's create a snapshot and overwrite the testfile
    # btrfs subvolume snapshot / /snap1
    # time dd if=/dev/zero of=/testfile bs=8k count=1M
    dd: writing `/testfile': No space left on device
    491105+0 records in
    491104+0 records out
    4023123968 bytes (4.0 GB) copied, 21.2399 s, 189 MB/s
    real     0m21.613s
    user     0m0.021s
    sys     0m3.325s
    <pre>
    So obviously the there is not enough space to maintain the original file and the snapshot file.
    Since I'm creating a complete new file, I guess that's to be expected.
    Let's try with a smaller file, and also check performance:
    <pre>
    # btrfs subvol delete /snap1
    Delete subvolume '//snap1'
    # time dd if=/dev/zero of=/testfile bs=8k count=500k
    512000+0 records in
    512000+0 records out
    4194304000 bytes (4.2 GB) copied, 21.7176 s, 193 MB/s
    real     0m21.726s
    user     0m0.024s
    sys     0m2.977s
    # time echo "This is a test to test the test" >> /testfile
    real     0m0.000s
    user     0m0.000s
    sys     0m0.000s
    # btrfs subvol snapshot / /snap1
    Create a snapshot of '/' in '//snap1'
    # df -k /
    Filesystem 1K-blocks Used Available Use% Mounted on
    /dev/sda3 16611328 6505736 8221432 45% /
    # time echo "This is a test to test the test" >> /testfile
    real     0m0.000s
    user     0m0.000s
    sys     0m0.000s
    # df -k /
    Filesystem 1K-blocks Used Available Use% Mounted on
    /dev/sda3 16611328 6505780 8221428 45% /
    # btrfs subvol delete /snap1
    Delete subvolume '//snap1'
    # df -k /
    Filesystem 1K-blocks Used Available Use% Mounted on
    /dev/sda3 16611328 6505740 8221428 45% /
    The snapshot occupied 40k
    # btrfs subvol snapshot / /snap1
    Create a snapshot of '/' in '//snap1'
    # time dd if=/dev/zero of=/testfile bs=8k count=500k
    512000+0 records in
    512000+0 records out
    4194304000 bytes (4.2 GB) copied, 21.3818 s, 196 MB/s
    real     0m21.754s
    user     0m0.019s
    sys     0m3.322s
    # df -k /
    Filesystem 1K-blocks Used Available Use% Mounted on
    /dev/sda3 16611328 10612756 4125428 73% /
    There was no performance impact, although the space occupied doubled.
    </pre>

  • Trying to understand PersistenceContextType.EXTENDED

    Hello,
    I'm trying to understand the PersistenceContextType.EXTENDED setting. It is my understanding that when I put this in my class, it means that the container managed transaction will span multiple method calls.
    I have a stateful bean:
    @Stateful(name = "StatefulContainerSessionEJB")
    public class StatefulContainerSessionEJBBean implements StatefulContainerSessionEJB, StatefulContainerSessionEJBLocal {
    @PersistenceContext(unitName = "Model",
    type = PersistenceContextType.EXTENDED)
    private EntityManager em;
    // implied REQUIRED transaction
    public void createAddress() {
    try {
    // create a new address
    Address addr = new Address();
    //... set addr fields
    System.out.println("Persist addr at: " + addr.getStreet());
    em.persist(addr);
    System.out.println("Persist of addr complete");
    } catch (Exception ex) {
    ex.printStackTrace();
    // transaction should still be alive here
    @Remove // this is what causes the transaction to end
    public void cancelTransaction() {
    System.out.println("Transaction rolledback");
    em.getTransaction().setRollbackOnly();
    And in my main code I have:
    StatefulContainerSessionEJB statefulContainerSessionEJB;
    public String createAddressThruStateful() {
    System.out.println("Create Address Thru Stateful Button hit....");
    try {
    final Context context = getInitialContext();
    statefulContainerSessionEJB = (StatefulContainerSessionEJB)context.lookup("StatefulContainerSessionEJB");
    statefulContainerSessionEJB.createAddress();
    } catch (Exception ex) {
    ex.printStackTrace();
    return null;
    public String cancelPartTimeTransaction() {
    System.out.println("Cancel Address Thru Stateful Button hit....");
    try {
    statefulContainerSessionEJB.cancelTransaction();
    } catch (Exception ex) {
    ex.printStackTrace();
    return null;
    First question is: am I using the Stateful bean correctly in main? i.e. its a class level variable and get instantiated in the createAddressThruStateful call.
    My second question is: when I run this code, my address get commited to the DB at the end of the createAddress() call. I didn't expect this to happen.
    Please straigten me out.
    Thanks,
    Chris

    please tell me what the inout in this coode means:A parameter that supplies input as well as accepts output is an INOUT parameter.

  • Trying to understand flash.media.Microphone

    Hi,
    I am new to flash/AS3 and currently trying to understand how to use flash.media.Microphone in my application.
    I have the following code to activate the microphone:
    var mic:Microphone = Microphone.getMicrophone();
    Security.showSettings("2");
    mic.setLoopBack(true);
    mic.setUseEchoSuppression(true);
    mic.addEventListener(StatusEvent.STATUS,micStatus);
    mic.addEventListener(ActivityEvent.ACTIVITY, activityHandler);
    This seems to be working fine and I get the "allow the use of the microphone" dialogue when I run the flash application.
    However, I go and add some other code in and after while I no longer get "allow the use of the microphone" when running my application. The microphone is still loaded can micStatus gets called, but the microphone just stays muted, so I don't get the echo back as configured with mic.setLoopBack(true).
    Initially I thought that maybe this is because something in my code, so I went back to my initial code again, but still get no  "allow the use of the microphone" dialogue and the microphone stays muted.
    If I create a new AS3 project and copy the code there is works again. This makes me think that maybe I am missing something. Do I need to release the microphone somehow after use. Saying that if I restart my computer, the projects that stopped displaying  "allow the use of the microphone" will still not display them.
    Really confused about this. Anyone have any pointers what I am doing wrong?
    regards,
    Olli

    Hi,
    Are you trying to download Adobe Flash Media Live Encoder 3.2? Could you please try again from here : https://www.adobe.com/cfusion/entitlement/index.cfm?e=fmle3 ?
    Hope this helps.
    Thanks,
    Apurva

  • Understanding Regex replace method call involving delegate

    Hello,
    I am trying to understand the $regex.replace static method call below (I came across this code snippet in the cookbook).
    $replacer = {
    param($match)
    $chars = $match.Groups[0].Value.ToCharArray()
    [Array]::Reverse($chars)
    $chars -join ''
    $regex = [Regex] "\w+"
    $regex.Replace("Hello World wide", $replacer)
    What I do not understand is the below overloaded definitions for replace method do not seem to match the above replace call. So how exactly is this working? The above call has 2 parameters passed where as none of the below overloads have less than
    3 parameters.
    PS C:\WINDOWS> [regex]::replace
    OverloadDefinitions
    static string Replace(string input, string pattern, string replacement)
    static string Replace(string input, string pattern, string replacement, System.Text.RegularExpressions.RegexOptions options)
    static string Replace(string input, string pattern, string replacement, System.Text.RegularExpressions.RegexOptions options, timespan matchTimeout)
    static string Replace(string input, string pattern, System.Text.RegularExpressions.MatchEvaluator evaluator)
    static string Replace(string input, string pattern, System.Text.RegularExpressions.MatchEvaluator evaluator, System.Text.RegularExpressions.RegexOptions options)
    static string Replace(string input, string pattern, System.Text.RegularExpressions.MatchEvaluator evaluator, System.Text.RegularExpressions.RegexOptions options, timespan
    matchTimeout)

    What you are looking at are the static methods ([regex]::) and their appropriate parameters which in this case have a minimum of 3 parameters to properly perform the Replace using the input, pattern and replacement
    value. If you were to use the constructor of [regex] to create a pattern like this:
    $Regex = [regex]'\w'
    You will see that the Replace method here allows for only 2 parameters because you have already satisfied the pattern when you created the Regex object.
    $Regex.Replace
    OverloadDefinitions
    string Replace(string input, string replacement)
    string Replace(string input, string replacement, int count)
    string Replace(string input, string replacement, int count, int startat)
    string Replace(string input, System.Text.RegularExpressions.MatchEvaluator evaluator)
    string Replace(string input, System.Text.RegularExpressions.MatchEvaluator evaluator, int count)
    string Replace(string input, System.Text.RegularExpressions.MatchEvaluator evaluator, int count, int startat)
    Boe Prox
    Blog |
    Twitter
    PoshWSUS |
    PoshPAIG | PoshChat |
    PoshEventUI
    PowerShell Deep Dives Book

Maybe you are looking for

  • Logic Pro X In, Most Other Functions Out

    Anyone else have this problem?  Since installing Logoc Pro X onto my MacBook Pro (purchased March 2013, 2.3 GHz Intel Core i7, 8 GB, OS 10.8.4) I've lost use of my Epson printer, Toast Titanium, and my internal disc drive.  Suggestions?

  • Owb versus oem

    so. i worked with oem (olap area). i created some measures and all. i created de user inteface with jdeveloper and bi beans 10g. now i want to test owb. what is the diference between them? owb is only for olap? which one is better? can i use jdev&bi

  • Oracle sql to outer join based on reg exp

    Hi, I am expecting output like (3). I want to join two tables with regex. join condition . For example, in table1.string(abcYYMMDD.txt) I want to match date part (YYMMDD) wit any possible number in Table2.string (abc150420.txt) Please suggest. (1) ta

  • Screensaver in Windows 7 Pro

    I had a keyboard shortcut set in Windows XP that let me turn on the screensaver immediately (I used Ctrl+Alt+Z to get a blank screen). There is no obvious way of setting a keyboard shortcut to the screensaver options in Windows 7 Pro - at least, I ha

  • Where can I find print page setup for firefox version 29?

    Hello, Can you please tell me where I can find Print -> Page Setup section for latest firefox version 29? I need to change header & footers info. Thank you. Best, Young