0

This is my first attempt at Android coding. We have a responsive web site and I call myself writing the code for an android app so that people and simply click on the icon after downloading the app and hit our website. On the Simulator, the app works fine on the various test phone, but when I upload APK for distribution and someone downloads and tries to run it, it crashes even before the splash screen is seen. Can some one please look at my code and tell me what's wrong. It seems to only crash on Android software version 6.0 or higher. On the old phones and tablets it run fine. Here are copies of my "SplashScreenActivity.java, my MainActivity.java, and my AndroidManifest.xml from Android Studios version 3.2.1. Any help would be appreciated.

SplashScreenActivity.java

    package com.wastefreemail.wfmconnect;
    import android.content.Intent;
    import android.support.v7.app.AppCompatActivity;
    import android.os.Bundle;
    import android.view.Window;
    import android.view.WindowManager;
    public class SplashScreenActivity extends AppCompatActivity {

    private int SLEEP_TIMER = 3;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);




        requestWindowFeature(Window.FEATURE_NO_TITLE);
        getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN, WindowManager.LayoutParams.FLAG_FULLSCREEN);
        setContentView(R.layout.activity_splash_screen);
        getSupportActionBar().hide();


        LogoLauncher logoLauncher = new LogoLauncher();
        logoLauncher.start();


    }

    private class LogoLauncher extends Thread{
      public void run(){
          try{
              sleep(1000 * SLEEP_TIMER);
          }catch(InterruptedException e){
              e.printStackTrace();

          }

          Intent intent = new Intent(SplashScreenActivity.this,         MainActivity.class);
          startActivity(intent);
          SplashScreenActivity.this.finish();
      }
    }
}

MainActivit.java

    package com.wastefreemail.wfmconnect;


    import android.app.Activity;
    import android.support.v7.app.AppCompatActivity;
    import android.os.Bundle;
    import android.view.Window;
    import android.view.WindowManager;
    import android.webkit.WebSettings;
    import android.webkit.WebView;
    import android.webkit.WebViewClient;



    public class MainActivity extends Activity {

    public WebView web1;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        requestWindowFeature(Window.FEATURE_NO_TITLE);
        setContentView(R.layout.activity_main);

        WebView web1 = (WebView)findViewById(R.id.web1);
        WebSettings webSettings = web1.getSettings();
        webSettings.setJavaScriptEnabled(true);
        web1.loadUrl("https://www.wastefreemail.com");
        web1.setWebViewClient(new WebViewClient());
    }
 }

AndroidManifest.xml

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.wastefreemail.wfmconnect">

<uses-permission android:name="android.permission.INTERNET"></uses-permission>

<application
    android:allowBackup="true"
    android:icon="@mipmap/ic_launcher"
    android:label="@string/app_name"
    android:roundIcon="@mipmap/ic_launcher_round"
    android:supportsRtl="true"
    android:theme="@style/AppTheme">
    <activity android:name=".MainActivity">

    </activity>
    <activity android:name=".SplashScreenActivity">
        <intent-filter>
            <action android:name="android.intent.action.MAIN" />

            <category android:name="android.intent.category.LAUNCHER" />
        </intent-filter>
    </activity>
</application>

</manifest>
Thientvse
  • 1,753
  • 1
  • 14
  • 23
  • Share your build gradle file so we can see your minimum and maximum sdk version. – Zankrut Parmar Oct 16 '18 at 15:24
  • And if possible connect one real android phone to your pc and post logcat here. – Zankrut Parmar Oct 16 '18 at 15:30
  • Zankrut, Here is a copy of my build.gradle (Module: app) apply plugin: 'com.android.application' android { compileSdkVersion 28 defaultConfig { applicationId "com.wastefreemail.wfmconnect" minSdkVersion 15 targetSdkVersion 28 versionCode 10 versionName "1.2.7" testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner" – stefan sanders Oct 16 '18 at 17:48
  • Zankrut, I'm noticing that the app works on some phones, but not others. Here is my current list: It works on the following: Samsung 8.0, LG 8.1, LG 7.0, Alcatel 8.1. The following it did not work on: Samsung 8.1, Motorola 8.1. I'm surprise that the same software version works on some phones, but not others, is there anything I can do to get it to work on all or most of them? – stefan sanders Oct 16 '18 at 17:52

2 Answers2

0

try this,

enter image description here

manifest file

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    package="com.example.chetan.testapp">

    <uses-permission android:name="android.permission.INTERNET"/>

    <application
        android:allowBackup="true"
        android:icon="@mipmap/ic_launcher"
        android:label="@string/app_name"
        android:roundIcon="@mipmap/ic_launcher_round"
        android:supportsRtl="true"
        android:theme="@style/AppTheme">
        <activity android:name=".MainActivity">
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />

                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>
        </activity>
    </application>

</manifest>

MainActivity.java

package com.wastefreemail.wfmconnect;



   import android.app.Activity;
import android.os.Bundle;
import android.view.Window;
import android.webkit.WebSettings;
import android.webkit.WebView;
import android.webkit.WebViewClient;



public class MainActivity extends Activity {

    public WebView web1;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
       // requestWindowFeature(Window.FEATURE_NO_TITLE);
        setContentView(R.layout.activity_main);

        web1 = (WebView)findViewById(R.id.webView);
        WebSettings webSettings = web1.getSettings();
        webSettings.setJavaScriptEnabled(true);
        web1.loadUrl("http://www.wastefreemail.com/");
        web1.setWebViewClient(new WebViewClient());
    }
}

xml

<WebView
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:id="@+id/webView"
        app:layout_constraintBottom_toBottomOf="parent"
        app:layout_constraintLeft_toLeftOf="parent"
        app:layout_constraintRight_toRightOf="parent"
        app:layout_constraintTop_toTopOf="parent" />

Hope it's help full.

chetan mahajan
  • 349
  • 4
  • 15
  • Thanks for the reply, still not working on a real phone, works great a simulator. Just to be sure the only thing you changed was the setContentView(R.layout.activity_splash_screen) and you changed the URL to google.com. It would help a lot if I could get it to fail on a simulator. Any Ideals on how to make that happen? I feel the simulator is really not an example of the real phones since I not getting the same results from both. – stefan sanders Oct 16 '18 at 14:21
  • it's working for my mobile phone . what url you load – chetan mahajan Oct 16 '18 at 14:26
  • One addition to my previous comments, you also commented out the requestWindowFeature(Window.Feature_NO_TITLE) statement. – stefan sanders Oct 16 '18 at 14:38
  • Chetan Mahajan, I tried www.wastefreemail.com and nike.com – stefan sanders Oct 16 '18 at 14:40
  • wait i'm try both link – chetan mahajan Oct 16 '18 at 14:42
  • chetan Mahajan, nothing in the logcat. Is there a way to see the error info from a real phone not plugged into the computer. I've had a number of people running the app from their phones from various locations and they all fail. – stefan sanders Oct 16 '18 at 14:45
  • @stefansanders , it's working in morning but i'm try that time is not load any url. i'm try to solve. – chetan mahajan Oct 16 '18 at 15:05
  • Hi Chetan, thanks for the update. if you don't mind me asking, what Manufacture of phone did you use and what was the software version? I only ask because I was testing with the following phones in the store and getting different results based on the above mentioned question. My results showed the following: Samsung 8.0 it worked, on the Samsung 8.1 crashed. On the LG 8.1 and 7.0 software it work. On the Alcatel 8.1 software it worked, but on the Motorola 7.0 and 8.1 it di not work. I was surprise to see different results from the same software version. – stefan sanders Oct 16 '18 at 18:41
  • Hey Guys, could the problem be the SplashScreenActivity.java since that's the first page it tries to load and it crashes immediately? – stefan sanders Oct 16 '18 at 20:48
  • Chetan, I tried your updates, still not working. Still crashing right away on a real phone. The latest test was on a Samsung Phone, software version 6.0.1 – stefan sanders Oct 16 '18 at 21:07
  • my mibile is mi note 5. os is 8.1. it's perfect working for me , no crash. forget about splashscreen and only run mainActivity.java . you go to manifest file and LAUNCHER the mainActivity file only, try it. – chetan mahajan Oct 17 '18 at 00:40
  • Chetan, I think I see the problem. My Splashscreen image is too big (Bitmap is big) for some devices. If I add the statements "android: hardwareAccelerated= "false" and "android:largeHeap="true", everything seems to work on previously failed test phones. Is it better to do it this way or better to replace the image with a small .png file, also if replace is better, what size should the replacement image be? Thanks. – stefan sanders Oct 18 '18 at 18:54
  • Stefan, read this link : https://stackoverflow.com/questions/13487124/android-splash-screen-sizes-for-ldpi-mdpi-hdpi-xhdpi-displays-eg-1024x76 Hope it's help – chetan mahajan Oct 19 '18 at 07:09
0

Looks like there may be a problem in your splashscreen activity. Try below code and let me know for further updates.

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    requestWindowFeature(Window.FEATURE_NO_TITLE);
    this.getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,WindowManager.LayoutParams.FLAG_FULLSCREEN);
    setContentView(R.layout.activity_splash_screen);

    new Handler().postDelayed(new Runnable() {
        @Override
        public void run() {

            Intent intent = new Intent(SplashScreenActivity.this,MainActivity.class);
            startActivity(intent);
            finish();
        }
    },5000); //here 5000 represents 5 seconds. Change this according to your need.
}

Edit

If even that doesn't work then make a new style in your styles.xml file.

<style name="AppTheme.NoActionBar">
    <item name="windowActionBar">false</item>
    <item name="windowNoTitle">true</item>
</style>

And apply this style to your activity in your manifest.xml file.

<activity
    android:name=".SplashScreenActivity"
    android:theme="@style/AppTheme.NoActionBar" />

EDIT

That SupportActionBar method is throwing a Null Pointer exception. Use this code in your splash activity. It will resolve the issue.

    requestWindowFeature(Window.FEATURE_NO_TITLE);
    getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN, WindowManager.LayoutParams.FLAG_FULLSCREEN);
    setContentView(R.layout.activity_splash_screen);
    try{
        getSupportActionBar().hide();
    } catch (NullPointerException e){
        e.printStackTrace();
    }
Zankrut Parmar
  • 1,872
  • 1
  • 13
  • 28
  • Hi Zankrut, made all of the changes, still no luck. – stefan sanders Oct 17 '18 at 18:05
  • Zankrut, I did notice one additional thing, If I comment out "setContentView(R.layout.activity_splash_screen);" it does not crash and it takes me to the website on both, the real phone and the simulator, but of course, no I get a page for the Splashscreen. – stefan sanders Oct 17 '18 at 20:51
  • @stefansanders Use the second edit code in your splash activity. I reproduced your error and found the solution for that. – Zankrut Parmar Oct 18 '18 at 04:07
  • Hi Zankrut, I notice that the splashscreen image bitmap was too larger, I put the original code back and resize my image, everything work fine after that. Thank you so much for all of your help, and everyone else that helped as well. – stefan sanders Oct 19 '18 at 18:58