Closed. This question needs debugging details. It is not currently accepting answers.
Edit the question to include desired behavior, a specific problem or error, and the shortest code necessary to reproduce the problem. This will help others answer the question.
Closed 5 years ago.
Improve this question
My Application stops working after the Splash Screen - keep in mind that this is the very first Android App I have ever developed. Help would be greatly appreciated.
SplashScreen.java:
package tomperry.goodlife;
import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
public class SplashScreen extends Activity {
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.splash);
Thread timerThread = new Thread() {
public void run() {
try {
sleep(3000);
} catch (InterruptedException e) {
e.printStackTrace();
} finally {
Intent intent = new Intent();
startActivity(intent);
}
}
};
timerThread.start();
}
#Override
protected void onPause() {
super.onPause();
finish();
}
}
AndroidManifist.xml
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="tomperry.goodlife">
<application
android:allowBackup="true"
android:icon="#mipmap/ic_launcher"
android:label="#string/app_name"
android:theme="#style/AppTheme">
<activity android:name=".SplashScreen"
android:label="#string/app_name" >
<intent-filter>
<action android:name="android.intent.action.MAIN"
></action>
<category android:name="android.intent.category.LAUNCHER"/>
</intent-filter>
</activity>
<activity android:name=".MainActivity"
android:label="#string/app_name">
<intent-filter>
<action android:name="tomperry.goodlife.MAINACTIVITY" />
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
</activity>
</application>
</manifest>
Your Intent is empty. You did not tell where to go. Replace it on your finally block -
Intent intent = new Intent(SplashScreen.this, NextActivity.class); //Change "NextActivity" as your need
startActivity(intent);
finish();
You haven't given reference to main activity.
try this
Intent intent = new Intent(getApplicationContext(), MainActivity.class);
startActivity(intent);
instead of
Intent intent = new Intent();
startActivity(intent);
Remove intent filter from Main Activity in Manifest file
<intent-filter>
<action android:name="tomperry.goodlife.MAINACTIVITY" />
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
Just replace your finally block with this:
startActivity(new Intent(Splashscreen.this,MainActivity.class));
You did not add the destination where to go. In finally block your Intent is empty. So change this code line into finally block:
Intent intent = new Intent();
to
Intent intent = new Intent( SplashScreen.this, MainActivity.class);
Related
<application
android:allowBackup="true"
android:icon="#drawable/logo"
android:label="App Name"
android:roundIcon="#drawable/logo"
android:supportsRtl="true"
android:requestLegacyExternalStorage="true"
android:theme="#style/maintheme"
android:usesCleartextTraffic="true"
tools:ignore="GoogleAppIndexingWarning"
tools:replace="android:icon, android:allowBackup"
>
this activity is splash screen activity below
<activity
android:name=""
android:exported="true">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
this activity is Folder activity activity below
<activity
android:name= ""
android:theme= ""
android:configChanges="orientation|keyboardHidden|screenSize"
android:exported="true" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity android:name=".MainActivity"
android:configChanges="orientation|keyboardHidden|screenSize"
android:exported="true">
</activity>
<activity android:name="" android:theme=""/>
<activity android:name="" android:theme="" android:configChanges="orientation|keyboardHidden|screenSize"/>
</application>
the problem is when the app run it show the splash screen and then it
show the app keep closing,it doesn't start the main activity.
can i make the android manifest to make the splash screen show first and then the start main activity
You cannot use your manifest for this, you need to use an Intent.
Code Example that you need in your SplashScreen Activity:
Intent intent = new Intent(SplashScreen.this, YOURNEXTCLASS.class);
intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
startActivity(intent);
finish();
You can switch activities only from the java files.
Implement this in your OnCreate method.
SplashActivity.java
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
Intent intent = new Intent(this, MainActivity.class);
Timer timer = new Timer();
timer.schedule(new TimerTask() {
#Override
public void run() {
startActivity(intent);
finish();
}
}, 2000); ////wait 2s before doing the action
}
AndroidManifest.xml
<activity
android:name=".ui.activities.SplashActivity"
android:exported="true"
android:theme="#style/SplashScreen">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity
android:name=".ui.activities.MainActivity"
android:exported="true"/>
the simple method to do is use this in splashscreenactivity.java
Intent intent=new Intent(SplashScreen.this, YourClass.class);
startActivity(intent);
finish();
like this
public class SplashScreenActivity extends AppCompatActivity {
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_splash_screen);
new Handler().postDelayed(new Runnable() {
#Override
public void run() {
//This method will be executed once the timer is over
// Start your app main activity
Intent i = new Intent(SplashScreenActivity.this, MainActivity.class);
startActivity(i);
// close this activity
finish();
}
}, 3000);
}
}
Make Sure Your compileSdkVersion 31 and targetSdkVersion 30.
Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 5 years ago.
Improve this question
appA mainActivity:
public class MainActivity extends AppCompatActivity implements View.OnClickListener {
Button btnSendBroadcast;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
btnSendBroadcast = (Button) findViewById(R.id.btnSendBroadcast);
btnSendBroadcast.setOnClickListener(this);
}
#Override
public void onClick(View view) {
final Intent intent=new Intent();
intent.setAction("com.example.admin.chromium");
intent.putExtra("KeyName","code1id");
intent.addFlags(Intent.FLAG_INCLUDE_STOPPED_PACKAGES);
intent.setComponent(
new ComponentName("com.example.admin.chromiumsendmessage","com.example.admin.chromiumsendmessage.MainActivity"));
sendBroadcast(intent);
Toast.makeText(getApplicationContext(), "KeyName value sent to ChromiumSendMessage app" , Toast.LENGTH_SHORT).show();
}
}
appB manifest--
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.admin.chromiumsendmessage">
<uses-permission android:name="android.permission.SEND_SMS" />
<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>
<receiver android:name=".MyBroadcast"
android:enabled="true"
android:exported="true">
<intent-filter>
<action android:name="com.example.admin.chromium" />
</intent-filter>
</receiver>
</application>
</manifest>
appB receiver class:
public class MyBroadcast extends BroadcastReceiver {
String msg;
String name;
#Override
public void onReceive(Context context, Intent intent) {
msg = intent.getStringExtra("KeyName");
name= msg;
Toast.makeText(context, "value - " + name, Toast.LENGTH_SHORT ).show();
}
}
AppB manifest appA mainActivity
There are two Applications, appA & appB. In appA there is a button. In appA, if I click on the button it should send some value (String/Integer) to the appB without the use of ContentProvider or SharedPreference. Moreover, the appB should receiver the value in its' BroadcastReceiver class. Could anyone help me please?
I have added appA MainActivity code and Receiver class and Manifest from appB.
You can use sendBroadcast() method to send String value from one app to another.
However, first of all you need to register your receiver app in Manifest.
For instance, suppose you have two apps, App1 and App2.
App1 will send the String value and App2 will receive that value.
In your App1, code should be like this,
final Intent intent=new Intent();
intent.setAction("com.pkg.App1");
intent.putExtra("KeyName","code1id");
intent.addFlags(Intent.FLAG_INCLUDE_STOPPED_PACKAGES);
intent.setComponent(
new ComponentName("com.pkg.App2","com.pkg.App2.MyBroadcastReceiver"));
sendBroadcast(intent);
To receive this broadcast message in App2, write code in Manifest of your App2 following below:
<receiver android:name=".MyBroadcastReceiver"
android:enabled="true"
android:exported="true">
<intent-filter>
<action android:name="com.pkg.App1" />
</intent-filter>
</receiver>
FLAG_INCLUDE_STOPPED_PACKAGES flag is added to the intent before it is
sent to indicate that the intent is to be allowed to start a component
of a stopped application.
I developed an application and put that on app store. Afterwords i wanted to change the package name so i just changed the application ID in build.gradle so that it looks appropriate in link. I didn't change anything else not the package name, not the manifest file etc. Application worked fine but now it's showing an error of ActivityNotFound exception on the launcher activity which is called through a broadcast receiver although that activity is defined in manifest file. May i know where am i wrong at?
This is the manifest file coding:
<receiver android:name=".PowerConnectionReceiver">
<intent-filter>
<action android:name="android.intent.action.ACTION_POWER_CONNECTED" />
</intent-filter>
</receiver>
<activity
android:name=".BatteryChargerFast"
android:configChanges="orientation"
android:screenOrientation="portrait"
android:label="#string/app_name"
android:launchMode="singleTask">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
And below is the coding of broadcast Receiver:
public class PowerConnectionReceiver extends BroadcastReceiver {
private String TAG="PowerConnectionReceiver";
#Override
public void onReceive(Context context, Intent intent) {
Intent i = new Intent();
i.setClassName("packagename",
"packagename.BatteryChargerFast");
i.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
i.putExtra("fast", true);
context.startActivity(i);
}
}
the error states:
java.lang.RuntimeException: Unable to start receiver
packagename.PowerConnectionReceiver:
android.content.ActivityNotFoundException: Unable to find explicit
activity class {packagename/packagename.BatteryChargerFast}; have you
declared this activity in your AndroidManifest.xml?
When you change applicationId in gradle, it overrides the Manifest's id.
so you need to change your code from:
Intent i = new Intent();
i.setClassName("packagename",
"packagename.BatteryChargerFast");
To:
Intent i = new Intent();
i.setClassName("your.new.app.id",
"packagename.BatteryChargerFast");
or may be even simpler where you don't need to consider all this:
#Override
public void onReceive(Context context, Intent intent) {
Intent i = new Intent(context.getApplicationContext(), BatteryChargerFast.class);
i.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
i.putExtra("fast", true);
context.startActivity(i);
}
I have two activity as below in same project.
How do i launch the MainActivity from ServicesDemo? I have used the Intent but it does not launch MainActivity.
Mainfest i have only one:
<activity
android:name=".ServicesDemo" android:label="#string/app_name">
When the project launch it start this one:
public class ServicesDemo extends Activity implements OnClickListener {
public void onClick(View src) {
switch (src.getId()) {
case R.id.buttonpicture:
Intent i = new Intent(getBaseContext(), MainActivity.class);
startActivity(i);
break;
}
}
}
ServiceDemo needs to launch this also:
public class MainActivity extends Activity implements OnClickListener {
}
EDIT:
Main fest: multiple activity listed
<activity
android:name=".ServicesDemo" android:label="#string/app_name">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.HOME" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity android:name=".MainActivity" android:label="#string/app_name">
</activity>
Called activity which is needed:
Intent i = new Intent(getBaseContext(), MainActivity.class);
startActivity(i);
Add the activity you want to launch into the Manifest:
<activity android:name=".MainActivity" android:label="#string/app_name" />
Then you can launch it with an intent:
startActivity(new Intent(this, MainActivity.class));
startActivity(new Intent("your.package.MainActivity"));
Intent i = new Intent(this, MainActivity.class);
startActivity(i);
finish();
then you must declare your activity in the manifest
<activity
android:name=".MainActivity" android:label="#string/app_name">
then when i press f8 a i get : ZygoteInit$methodandargscaller.run() source not found
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.copyup"
android:versionCode="1"
android:versionName="1.0" >
<uses-sdk
android:minSdkVersion="8"
android:targetSdkVersion="17" />
<application
android:allowBackup="true"
android:icon="#drawable/ic_launcher"
android:label="#string/app_name"
android:theme="#style/AppTheme" >
<activity
android:name="com.example.copyup.MainActivity"
android:label="copy up" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity
android:name=".Game"
android:label="Copy Up">
</activity>
<activity
android:name=".Rules"
android:label="Copy Up!">
</activity>
<activity
android:name=".Scores"
android:label="Copy Up!">
</activity>
<activity
android:name=".LearnCircle"
android:label="Copy Up!">
</activity>
<activity
android:name=".LearnHoriz"
android:label="Copy Up!">
</activity>
<activity
android:name=".LearnVert"
android:label="Copy Up!">
</activity>
<activity
android:name=".LearnMenu"
android:label="Copy Up!">
</activity>
</application>
</manifest>
and my code:
package com.example.copyup;
import android.os.Bundle;
import android.app.Activity;
import android.content.Intent;
import android.view.View;
import android.widget.Button;
public class MainActivity extends Activity {
Button start, rules, hs, learn;
#Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
linktoxml();
start.setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {
Intent myIntent = new Intent(MainActivity.this, Game.class);
MainActivity.this.startActivity(myIntent);
}
});
/*
rules.setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {
Intent myIntent = new Intent(MainActivity.this, Rules.class);
MainActivity.this.startActivity(myIntent);
}
});
hs.setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {
Intent myIntent = new Intent(MainActivity.this, Scores.class);
MainActivity.this.startActivity(myIntent);
}
});
learn.setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {
Intent myIntent = new Intent(MainActivity.this, LearnMenu.class);
MainActivity.this.startActivity(myIntent);
}
});*/
//show shape, take reading after 4 seconds, compare with other, if true next, if false, end game
//dont make it complex with time reduce yet!!
}
private void linktoxml() {
start = (Button) findViewById(R.id.bcstart);
rules = (Button) findViewById(R.id.brules);
hs = (Button) findViewById(R.id.bhs);
learn = (Button) findViewById(R.id.blearn);
}
}
I have tried cleaning the project, re-writing the manifest and everything i can possible think of. It works if i comment out the links to the buttons in the code and leave them in the manifest but the moment i uncommnet them i get these errors, please help!!!
The problem is that the activity throw exception.
eclipse looks for the source code in android SDK and can't find it.
Just debug your code and find out where the code throw exception.
solved it, feeling pretty stupid now, needed bstart not bcstart when the button is defined.