Android does not immediately call Ondestory at finish (), how can I immediately callback ondestory after finish?

Source: Internet
Author: User

============ Problem Description ============


Private Myaidlservice Myaidlservice;
Private Serviceconnection connection = new Serviceconnection () {

@Override
public void onservicedisconnected (componentname name) {
}

@Override
public void onserviceconnected (componentname name, IBinder service) {
Myaidlservice = MyAIDLService.Stub.asInterface (service);
ListView list = (ListView) Findviewbyid (R.id.weidingdanlist); Load List
Setlistshow (list); Load List
}
};

public void OnCreate (Bundle savedinstancestate) {//Override OnCreate method

Super.oncreate (savedinstancestate);
Requestwindowfeature (Window.feature_no_title); Does not show the topmost bar
Setcontentview (R.layout.weidingdan);

Setlist ();//Display a list

Fanhui = (ImageButton) Findviewbyid (R.id.weidingdanfanhuibutton);
Fanhui.setimageresource (R.drawable.fanhui);

Fanhui.setonclicklistener (New Button.onclicklistener ()
{
@Override
public void OnClick (View arg0) {
Unbindservice (connection);
Finish ();
}
});
}

private void setlist () {//list here Wphoto is a picture with a content of "please later"
ListView list = (ListView) Findviewbyid (R.id.weidingdanlist);

Wphoto = (ImageView) Findviewbyid (R.id.wphoto);//Display picture
Wphoto.setimageresource (R.drawable.wphoto);//Display picture
Intent Intent = new Intent ("Com.example.servicetest.MyAIDLService"); Invoking the Service Load list
Bindservice (Intent, connection, bind_auto_create); Invoking the Service Load list
}


private void Setlistshow (ListView list) {
arraylistListitem.clear ();

Hashmap<string, object> map;
Map = new hashmap<string, object> ();
Map.put ("Itemtitle", "AAA");
Map.put ("Itemtext", "AAA");
Map.put ("Time", "AAA");
Map.put ("Image", R.drawable.kong);
Listitem.add (map);

Map = new hashmap<string, object> ();
Map.put ("Itemtitle", "BBB");
Map.put ("Itemtext", "BBB");
Map.put ("Time", "BBB");
Map.put ("Image", R.drawable.kong);
Listitem.add (map);
}
}

Build the adapter's item and the element corresponding to the dynamic array
Simpleadapter listitemadapter = new Simpleadapter (this,listitem,//data source
XML implementation of R.layout.list_items,//listitem
New string[] {"Itemtitle", "Itemtext", "Time", "Image"},
New int[] {r.id.weidingdantitle,r.id.weidingdantext,r.id.weidingdantime,r.id.weidingdanfrontimage}
);

Add and Show
List.setadapter (Listitemadapter);
Closeanim ();//make the picture disappear
}


private void Closeanim () {
Animation Animationscale;
Animationscale = new Scaleanimation (1f, 0f, 1f, 0f animation.relative_to_self, 0.5f,animation.relative_to_self, 0.5f);
Animationscale.setduration (5);
Animationscale.setfillafter (TRUE);
Wphoto.startanimation (Animationscale);
}



This program is because the list is loaded slowly, so, first display a "Please later" picture, and then load out the list after the picture disappears.

The above program, after clicking the Back button, will be returned to the previous activity, here is no problem. However, when you enter this activity again, the list is loaded first, then the picture "Please later" is displayed, and the picture disappears.

I guess it's because the finish () didn't execute ondestory () to have this effect. Is there a great God who can help me solve this problem??!!
Or can I execute ondestory () immediately after finish ()?

Help me!!!

============ Solution 1============


Well, you can do it when you're onresume.

============ Solution 2============


Finsh do you want to finish onresume,onstop,ondestory?

============ Solution 3============


The problem is not the finish destroy
What you want to achieve is completely unnecessary to consider these things, or the service is not used for this purpose.
Take a closer look at someone else's demo reference and don't take it for granted.

============ Solution 4============


Reference 5 Floor Sirenyizhi's reply:
Quote: Referring to the reply of the 3 floor davidleen29:

The problem is not the finish destroy
What you want to achieve is completely unnecessary to consider these things, or the service is not used for this purpose.
Take a closer look at someone else's demo reference and don't take it for granted.


Do you know how to write this? I read that the service can perform the following time-consuming procedures, but did not write how to write ..... I'm not going to use it. or novice, so seek the guidance of the Great God!

Service is also running in the main thread, how can go to perform time-consuming operation, time-consuming operation can create a new thread or use the system Asynctask

Android does not immediately call Ondestory at finish (), how can I immediately callback ondestory after finish?

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.