Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

430
Visualizações
KILL App's MainActivity on Startup if(networkState==false || null)

Good day friends of mine.

I want to add a functionality to my ANDROID application, which I think it is new to me... but it is new in the development world. The application runs very well at the moment... But I need to add this functionality as explained below.

Please see the sample picture below...which tells exactly what I want to do.

I want to check network connection state on Application Startup. If connection state is true, then, the application should load the MainActivity.xml. If connection state is false, then, the application should return a new String ("Error") message.

Please see my code sample below...in the onCreate() {} thread. NOTE: I am not proficient in android development please.

@Override
    protected void onCreate(Bundle savedInstanceState) {
        cm = (ConnectivityManager) getSystemService(Context.CONNECTIVITY_SERVICE);
        activeNetwork = cm.getActiveNetworkInfo();//this is line 91...
        Log.d("Network Info", "" + activeNetwork);//log the connection info

        if (activeNetwork != null && activeNetwork.isConnected()) {
            super.onCreate(savedInstanceState);
            setContentView(R.layout.activity_main);

            //initialize the status bar textview control
            statusBar = (TextView) findViewById(R.id.textViewStatusMsg);//status bar of the UI
            titleLogin = (TextView) findViewById(R.id.textViewLogin);//title text of the UI

If the above condition is TRUE, the application runs well but if the following condition below is FALSE, the application crashes with ANDROID's error message "Unfortunately, App has crashed!". Instead of it giving me its own message and crashing, I want to kill the app programmatically using the else...statement below.

} else {
            data = new String("NO NETWORK CONNECTION! TRY AGAIN...");
            return; //return the message data and kill the APP's UI here
        }
    }

Any help will suffice please... I am not well vested in android programming and development...

enter image description here

over 4 years ago · Santiago Trujillo
1 Respostas
Responde à pergunta

0

I guess the reason for crashing is because of misplaced of super.onCreate method.

Move this statement outside if block and either you can do a toast message or show an alert dialog.

If above solution didn't work, comment the crash stacktrace.

over 4 years ago · Santiago Trujillo Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda