android - Headless fragment with arguments, how to use Fragment.newInstance? -


i've been working through 3 different tutorials headless fragment open sockets , stay open through lifecycle changes. think i'm close there 1 final element escapes me. guts of fragment opening sockets , threads based on class works i'm not concerned part, @ least now. here relevant parts of fragment, rest left out make less torturous read. i'm trying pass in p2p group owner's ip , port. (no problems that)

public class connectionfragment extends fragment {      private inetaddress mgoaddress;     private int mgoport;     private client mclient;     private static final string tag = "connection";     private static final string client_tag = "client";     private server mserver;     private socket msocket;     private connectionfragmentlistener mlistener;       public static connectionfragment newinstance(inetaddress address, int port){         bundle bundle = new bundle();         bundle.putserializable("goaddress", address);         bundle.putint("goport", port);         connectionfragment fragment = new connectionfragment();         fragment.setarguments(bundle);          return fragment;     }       private void readbundle(bundle bundle){         if (bundle != null){             mgoaddress = (inetaddress)bundle.getserializable("goaddress");             mgoport = bundle.getint("goport");         }     }      @override     public void oncreate(bundle savedinstancestate) {         super.oncreate(savedinstancestate);         setretaininstance(true);         readbundle(getarguments());         mgoaddress = (inetaddress) getarguments().getserializable("goaddress");         mgoport = getarguments().getint("goport");          mserver = new server();      } 

then in activity this, giving group owner ip , port.

mconnection = connectionfragment.newinstance(goinetaddress, prefixedport); 

my question is, do next run mconnection? thank you.

you've got add fragment after creating it. since it's headless, won't need container id:

getsupportfragmentmanager()     .begintransaction()     .add(mconnection, tag)     .commit(); 

Comments

Popular posts from this blog

python - How to insert QWidgets in the middle of a Layout? -

python - serve multiple gunicorn django instances under nginx ubuntu -

module - Prestashop displayPaymentReturn hook url -