简体   繁体   中英

Need Modified Code Structure for MainActivity.java

I want to insert code in MainActivity of 'Webview' Project To code in MainActivity of 'Push Notification' project .

As I'm new to Android & Java, I have spent hell lot of time but unable to produce a solution.

Suggest solution for following code structure:

'Push Notification' Project

public class MainActivity extends AppCompatActivity {

   @Override
   protected void onCreate(Bundle savedInstanceState) {
       super.onCreate(savedInstanceState);
       setContentView(R.layout.activity_main);

 //------Code for push notification---------------------

   }

'Webview' Project

public class MainActivity extends Activity{

    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);

 //-----------Code for WebView------------

    }

    private class CustomWebViewClient extends WebViewClient {
        public boolean shouldOverrideUrlLoading(WebView view, String url) {
            //----------code-----------------
        }
    }

}

I have found solution myself. Hope others find it useful.

NOTE: Put push notification code before WebView code else it will not run push notification.

public class MainActivity extends Activity {

    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);

         //------Code for push notification---------------------

         //-----------Code for WebView------------

    }

    private class CustomWebViewClient extends WebViewClient {
        public boolean shouldOverrideUrlLoading(WebView view, String url) {
            //----------code-----------------
        }
    }
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM