android - Fragment should be static such that they can be re-instantiated by the system -
i using payumoney payment gateway in app, until decided generate signed apk. shows error: error:error: fragments should static such can re-instantiated system, , anonymous classes not static [validfragment]. generating normal apk though. here code:
public class oldpaymentactivity extends appcompatactivity implements magicretryfragment.activitycallback{ bundle bundle; string url; boolean canceltransaction = false; payuconfig payuconfig; private broadcastreceiver mreceiver = null; private string utf = "utf-8"; private boolean viewportwide = false; private webview mwebview; private boolean smspermission; private int storeoneclickhash; private string merchanthash; magicretryfragment magicretryfragment; string txnid = null; public oldpaymentactivity(){ } @override protected void oncreate(bundle savedinstancestate) { /** * when device runing out of memory dont want user restart payment. rather close , redirect them previous activity. */ if(savedinstancestate!=null){ super.oncreate(null); finish();//call activity u want activity being destroyed restarted }else { super.oncreate(savedinstancestate); } setcontentview(r.layout.activity_payments); mwebview = (webview) findviewbyid(r.id.webview); // webview.setwebcontentsdebuggingenabled(true); //region replace whole code commented code if not using custombrowser // replace whole code commented code if not using custombrowser. bundle = getintent().getextras(); payuconfig = bundle.getparcelable(payuconstants.payu_config); storeoneclickhash = bundle.getint(payuconstants.store_one_click_hash); mwebview = (webview) findviewbyid(r.id.webview); url = payuconfig.getenvironment() == payuconstants.production_env? payuconstants.production_payment_url : payuconstants.test_payment_url ; string [] list = payuconfig.getdata().split("&"); string merchantkey = null; (string item : list) { string[] items = item.split("="); if(items.length >= 2) { string id = items[0]; switch (id) { case "txnid": txnid = items[1]; break; case "key": merchantkey = items[1]; break; case "pg": if (items[1].contentequals("nb")) { viewportwide = true; } break; } } } try { class.forname("com.payu.custombrowser.bank"); final bank bank = new bank() { @override public void registerbroadcast(broadcastreceiver broadcastreceiver, intentfilter filter) { mreceiver = broadcastreceiver; registerreceiver(broadcastreceiver, filter); } @override public void unregisterbroadcast(broadcastreceiver broadcastreceiver) { if(mreceiver != null){ unregisterreceiver(mreceiver); mreceiver = null; } } @override public void onhelpunavailable() { findviewbyid(r.id.parent).setvisibility(view.gone); findviewbyid(r.id.trans_overlay).setvisibility(view.gone); } @override public void onbankerror() { findviewbyid(r.id.parent).setvisibility(view.gone); findviewbyid(r.id.trans_overlay).setvisibility(view.gone); } @override public void onhelpavailable() { findviewbyid(r.id.parent).setvisibility(view.visible); } @override public void onbackpressed(alertdialog.builder alertdialog){ toast.maketext(oldpaymentactivity.this, "payment activity onbackpressed", toast.length_short).show(); } @override public void onbackapproved(){ toast.maketext(oldpaymentactivity.this,"payment activity onbackapproved",toast.length_short).show(); } @override public void onbackcancelled(){ toast.maketext(oldpaymentactivity.this,"payment activity onbackcancelled",toast.length_short).show(); } }; bundle args = new bundle(); args.putint(bank.webview, r.id.webview); args.putint(bank.trans_layout, r.id.trans_overlay); args.putint(bank.main_layout, r.id.r_layout); args.putboolean(bank.viewportwide, viewportwide); args.putboolean(bank.auto_select_otp, false); args.putboolean(bank.auto_approve, true); args.putboolean(bank.back_button, true); args.putstring(bank.txn_id, txnid == null ? string.valueof(system.currenttimemillis()) : txnid); args.putstring(bank.merchant_key, merchantkey); smspermission = getintent().getbooleanextra(payuconstants.sms_permission, true);//default true args.putboolean(bank.merchant_sms_permission, smspermission); payusdkdetails payusdkdetails = new payusdkdetails(); args.putstring(bank.sdk_details, payusdkdetails.getsdkversionname()); // should cb send merchant hash app? args.putint(bank.store_one_click_hash, storeoneclickhash); if(getintent().getextras().containskey("showcustom")) { args.putboolean(bank.show_customrowser, getintent().getbooleanextra("showcustom", false)); } args.putboolean(bank.show_customrowser, true); bank.setarguments(args); findviewbyid(r.id.parent).bringtofront(); try { getsupportfragmentmanager().begintransaction().setcustomanimations(r.anim.fade_in, r.anim.cb_face_out).add(r.id.parent, bank).commit(); }catch(exception e) { e.printstacktrace(); finish(); } initmagicretry(); mwebview.setwebchromeclient(new payuwebchromeclient(bank)); mwebview.setwebviewclient(new payuwebviewclient(bank, magicretryfragment,merchantkey)); //mwebview webview object magicretryfragment.setwebview(mwebview); // mr integration - initmrsettingsfromsharedpreference magicretryfragment.initmrsettingsfromsharedpreference(this); mwebview.posturl(url, payuconfig.getdata().getbytes()); // (new payuutils()).deviceanalytics(oldpaymentactivity.this, bank.version, "data", txnid); //oqms } catch (classnotfoundexception e) { mwebview.getsettings().setcachemode(websettings.load_no_cache); mwebview.getsettings().setsupportmultiplewindows(true); mwebview.getsettings().setjavascriptcanopenwindowsautomatically(true); // setting view port nb if(viewportwide){ mwebview.getsettings().setusewideviewport(viewportwide); } // hiding overlay view transoverlay = findviewbyid(r.id.trans_overlay); transoverlay.setvisibility(view.gone); mwebview.addjavascriptinterface(new object() { @javascriptinterface public void onsuccess() { onsuccess(""); } @javascriptinterface public void onsuccess(final string result) { runonuithread(new runnable() { @override public void run() { intent intent = new intent(); intent.putextra("result", result); if(storeoneclickhash == payuconstants.store_one_click_hash_server && null != merchanthash){ intent.putextra(payuconstants.merchant_hash, merchanthash); } setresult(activity.result_ok, intent); finish(); } // } }); } @javascriptinterface public void onfailure() { onfailure(""); } @javascriptinterface public void onfailure(final string result) { runonuithread(new runnable() { @override public void run() { intent intent = new intent(); intent.putextra("result", result); setresult(result_canceled, intent); finish(); } }); } @javascriptinterface public void onmerchanthashreceived(final string result) { runonuithread(new runnable() { @override public void run() { switch (storeoneclickhash){ case payuconstants.store_one_click_hash_mobile: try { jsonobject hashobject = new jsonobject(result); new payuutils().storeinsharedpreferences(oldpaymentactivity.this, hashobject.getstring(payuconstants.card_token), hashobject.getstring(payuconstants.merchant_hash)); } catch (jsonexception e) { e.printstacktrace(); } break; case payuconstants.store_one_click_hash_server: merchanthash = result; break; case payuconstants.store_one_click_hash_none: break; } } }); } }, "payu"); mwebview.setwebchromeclient(new webchromeclient() ); mwebview.setwebviewclient(new webviewclient()); mwebview.getsettings().setjavascriptenabled(true); mwebview.getsettings().setdomstorageenabled(true); mwebview.posturl(url, payuconfig.getdata().getbytes()); } /*mwebview.getsettings().setjavascriptenabled(true); mwebview.getsettings().setdomstorageenabled(true); // url = payuconfig.getenvironment() == payuconstants.production_env? payuconstants.production_payment_url : payuconstants.mobile_test_payment_url ; mwebview.posturl(url, encodingutils.getbytes(payuconfig.getdata(), "base64"));*/ } @override public boolean oncreateoptionsmenu(menu menu) { // inflate menu; adds items action bar if present. getmenuinflater().inflate(r.menu.menu_payments, menu); return true; } @override public boolean onoptionsitemselected(menuitem item) { // handle action bar item clicks here. action bar // automatically handle clicks on home/up button, long // specify parent activity in androidmanifest.xml. int id = item.getitemid(); //noinspection simplifiableifstatement if (id == r.id.action_settings) { return true; } return super.onoptionsitemselected(item); } @override public void ondestroy(){ super.ondestroy(); } @override protected void onstop() { super.onstop(); //invalidate dialogfragment avoid stupid memory leak if (magicretryfragment != null) { magicretryfragment = null; } } private void initmagicretry() { fragmentmanager fragmentmanager = getsupportfragmentmanager(); magicretryfragment = new magicretryfragment(); bundle newinformationbundle = new bundle(); newinformationbundle.putstring(magicretryfragment.key_txnid, txnid); magicretryfragment.setarguments(newinformationbundle); map<string, string> urllist = new hashmap<string, string>(); urllist.put(url, payuconfig.getdata()); magicretryfragment.seturllistwithpostdata(urllist); fragmentmanager.begintransaction().add(r.id.magic_retry_container, magicretryfragment, "magicretry").commit(); // magicretryfragment = (magicretryfragment) fragmentmanager.findfragmentby(r.id.magicretry_fragment); togglefragmentvisibility(util.hide_fragment); magicretryfragment.iswhitelistingenabled(true); } public void togglefragmentvisibility(int flag){ fragmenttransaction ft = getsupportfragmentmanager().begintransaction(); if (!isfinishing()) { if (flag == util.show_fragment) { // show fragment ft.show(magicretryfragment).commitallowingstateloss(); } else if (flag == util.hide_fragment) { // hide fragment ft.hide(magicretryfragment).commitallowingstateloss(); // ft.hide(magicretryfragment); } } } @override public void showmagicretry() { togglefragmentvisibility(util.show_fragment); } @override public void hidemagicretry() { togglefragmentvisibility(util.hide_fragment); } }
Comments
Post a Comment