this the first part of the code with the splash screen code
public class MainActivity extends AppCompatActivity {
private static final int SPLASH_TIME_OUT = 1000;
private static final String FILE_NAME = "example.txt";
EditText mEditText;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
mEditText = findViewById(R.id.edit_text);
new Handler().postDelayed(new Runnable() {
#Override
public void run() {
Intent homeIntent = new Intent(MainActivity.this, HomeActivity.class);
startActivity(homeIntent);
finish();
}
},SPLASH_TIME_OUT);
the first thing that comes out after i run the app is the main activity and not the splash screen
You have to specify your activity Actions by using Intent Filter ,
Intent Filters specifies the types of intents that an activity, service, or broadcast receiver can respond to. An intent filter declares the capabilities of its parent component — what an activity or service can do and what types of broadcasts a receiver can handle. It opens the component to receiving intents of the advertised type, while filtering out those that are not meaningful for the component.
As in For your Case, You have to specify that MainActivity/SplashActivity should be on Launcher Mode(Launcher mode is an instruction for Android OS which specifies how the activity should be launched), you have to use Intent filter and specify Activity Actions ,
*Must go through this Article App Manifest Overview
Add this in your Manifest file within <Application> Tag
<activity android:name=".MainActivity">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
In your AndroidManifest file, SplashActivity must be set as Launcher activity. Check the name of the Splash screen activity file in your project.
<activity android:name=".SplashActivity">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
Can you share your manifest? Launch Activity should be Splash Activity.
Which Activity you want the application to start with, you need to add IntentFilter in that Activity in the Manifest file.
<activity android:name="SplashActivity"
android:label="#string/app_name">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER"/>
</intent-filter>
</activity>
Related
when you click on a video android give you some suggestion app to open the video i wnat to add my app to the list. name of the list is complete action using and this doc is related https://developer.android.com/training/basics/intents/filters.html
but i am beginner and dont know how to use the doc for video
<activity android:name="ShareActivity">
<intent-filter>
<action android:name="android.intent.action.SEND"/>
<category android:name="android.intent.category.DEFAULT"/>
<data android:mimeType="text/plain"/>
<data android:mimeType="image/*"/>
</intent-filter>
</activity>
and please guide me how to handle the intent in activity
Put this code into your manifest in your activity tag :
<intent-filter tools:ignore="AppLinkUrlError">
<action android:name="android.intent.action.VIEW" />
<category android:name="android.intent.category.DEFAULT" />
<category android:name="android.intent.category.BROWSABLE" />
<data android:mimeType="video/*" />
</intent-filter>
It will show your app into a suggestion list whenever user selects a video file from his phone. ALthough, you need to handle the further actions in your videoplayer activity.
Because this tag will only help you getting your into a suggestion list, to play a selected video, you have to use intent to get the selected video uri. You can find the examples of playing a video file like this on the internet easily.
There are two ways I know to achieve this kind of things.
BroadcastReceiver
Manifest.xml
<application
...
<!-- BROADCAST RECEIVER -->
<receiver
android:name="com.package.app.Broadcaster"
android:label="#string/app_name" >
<intent-filter>
<action android:name="android.intent.action.SEND"/>
<category android:name="android.intent.category.DEFAULT"/>
<data android:mimeType="text/plain"/>
<data android:mimeType="image/*"/>
</intent-filter>
</receiver>
<activity
...
</activity>
...
</application>
com.package.app.Broadcaster
public final class Broadcaster extends BroadcastReceiver
{
#Override
public final void onReceive(final Context context, final Intent intent) {
//Activity to handle the files.
intent.setClass(context, MainActivity.class);
//RuntimeException without this flag.
intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
context.startActivity(intent);
}
}
Service
Manifest.xml
<application
...
<!-- SERVICE -->
<service
android:enabled="true"
android:name="com.package.app.Servicer"
android:label="#string/app_name" >
<intent-filter>
<action android:name="android.intent.action.SEND"/>
<category android:name="android.intent.category.DEFAULT"/>
<data android:mimeType="text/plain"/>
<data android:mimeType="image/*"/>
</intent-filter>
</service>
<activity
...
</activity>
...
</application>
com.package.app.Servicer
public final class Servicer extends Service
{
#Override
public final int onStartCommand(final Intent intent, final int flags, final int startId) {
//Activity to handle the files
intent.setClass(this, MainActivity.class);
//RuntimeException without this flag.
intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
startActivity(intent);
//Stop this service.
stopSelfResult(startId);
return super.onStartCommand(intent, flags, startId);
}
#Override
public final IBinder onBind(final Intent intent) {
return null;
}
}
I have an application that has two main activities MainActivity1 and MainActivity2.
I have the Intent filter for the launcher on MainActivity1
activity android:name=".MainActivity1">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
what I want is to be able to switch the launcher activity in my settings activity.
Is that possible and how will it work?
All I did was to create a shared preference boolean the know which activity to open. Then from MainActivity1 I used an intent to go to MainActivity2
Intent intent = getIntent();
boolean firstTimeOpening = intent.getBooleanExtra("BOOLEAN_FIRST_TIME_OPENING", true);
SharedPreferences preferences = getSharedPreferences("SHARED_PREFERENCES", MODE_PRIVATE);
boolean startAppWithActivity1 = preferences.getBoolean(START_APP_WITH_ACTIVITY1, true);
if(!startAppWithActivity1 && firstTimeOpening){ startActivity(new Intent(MainActivity1.this, MainActivity2.class));
}
Easy enough. The firstTimeOpening boolean makes sure the the switching
of activity occurs only when the application is just opened
I recently was studying making an AlarmReminder on youtube by this man's tutorial videos: DelaroyStudios.
Anyway... I followed his tutorial and made it work on a separate app. So next I modified it to the way I want my alarmreminder to be and tried to add it to my activity, however when I click the button routing to its activity launcher, it won't go off. By the way here's the repo: https://github.com/delaroy/AlarmReminder
I tried debugging but I can't see errors, so I really don't know where to start in fixing this part. But I suspect its on the dependencies on the gradle perhaps? or some other factor? Anyway please take a look at my code where I suspect the problem might be coming from.
Here's the manifests:
My Manifest
<application
android:name=".FireApp"
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="com.loginpack.splash">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity android:name="com.loginpack.LoginActivity" />
<activity android:name=".MainActivity" />
<activity android:name="com.Welcome.Welcome" />
<activity android:name="com.Welcome.CalendarActivity" />
<activity android:name="com.Welcome.Video" />
<activity android:name=".Profile" />
<activity android:name="com.Welcome.Image">
<intent-filter>
<action android:name="android.intent.action.VIEW" />
<category android:name="android.intent.category.DEFAULT" />
<data android:mimeType="image/*" />
</intent-filter>
</activity>
<activity android:name="com.alarmreminder.MainReminder">
<intent-filter>
<action android:name="android.intent.action.VIEW" />
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
</activity>
<activity android:name="com.alarmreminder.AddReminderActivity"
android:label="#string/title_activity_add_reminder"
android:parentActivityName="com.alarmreminder.MainReminder"
android:theme="#style/AppTheme">
<!-- Parent activity meta-data to support 4.0 and lower -->
<meta-data
android:name="android.support.PARENT_ACTIVITY"
android:value="com.alarmreminder.MainReminder"
/>
</activity>
<activity android:name="com.Welcome.Info" />
<activity android:name=".Profile2" />
<activity android:name=".Profile3"/>
I checked the code and I suspect nothing except for some deprecated codes that were usually couldn't have affected the overall performance of the activity to the point that it can't even be opened and debugged. Please help me find a way to make this work. or perhaps if you know any method for me to debug activities without any errors showing. Oh and by the way this is what shows in the Verbose when I click on the activity.
Here's the code of the Activity mentioned:
public class MainReminder extends AppCompatActivity implements LoaderManager.LoaderCallbacks<Cursor> {
private FloatingActionButton mAddReminderButton;
private Toolbar mToolbar;
AlarmCursorAdapter mCursorAdapter;
AlarmReminderDbHelper alarmReminderDbHelper = new AlarmReminderDbHelper(this);
ListView reminderListView;
private static final int VEHICLE_LOADER = 0;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_mainalarm);
mToolbar = findViewById(R.id.toolbar);
setSupportActionBar(mToolbar);
mToolbar.setTitle(R.string.app_name);
reminderListView = findViewById(R.id.list);
View emptyView = findViewById(R.id.empty_view);
reminderListView.setEmptyView(emptyView);
mCursorAdapter = new AlarmCursorAdapter(this, null);
reminderListView.setAdapter(mCursorAdapter);
reminderListView.setOnItemClickListener(new AdapterView.OnItemClickListener() {
#Override
public void onItemClick(AdapterView<?> adapterView, View view, int position, long id) {
Intent intent = new Intent(MainReminder.this, AddReminderActivity.class);
Uri currentVehicleUri = ContentUris.withAppendedId(AlarmReminderContract.AlarmReminderEntry.CONTENT_URI, id);
// Set the URI on the data field of the intent
intent.setData(currentVehicleUri);
startActivity(intent);
}
});
mAddReminderButton = findViewById(R.id.fab);
mAddReminderButton.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
Intent intent = new Intent(v.getContext(), AddReminderActivity.class);
startActivity(intent);
}
});
getLoaderManager().initLoader(VEHICLE_LOADER, null, this);
}
#Override
public Loader<Cursor> onCreateLoader(int i, Bundle bundle) {
String[] projection = {
AlarmReminderContract.AlarmReminderEntry._ID,
AlarmReminderContract.AlarmReminderEntry.KEY_TITLE,
AlarmReminderContract.AlarmReminderEntry.KEY_DATE,
AlarmReminderContract.AlarmReminderEntry.KEY_TIME,
AlarmReminderContract.AlarmReminderEntry.KEY_REPEAT,
AlarmReminderContract.AlarmReminderEntry.KEY_REPEAT_NO,
AlarmReminderContract.AlarmReminderEntry.KEY_REPEAT_TYPE,
AlarmReminderContract.AlarmReminderEntry.KEY_ACTIVE
};
return new CursorLoader(this, // Parent activity context
AlarmReminderContract.AlarmReminderEntry.CONTENT_URI, // Provider content URI to query
projection, // Columns to include in the resulting Cursor
null, // No selection clause
null, // No selection arguments
null); // Default sort order
}
#Override
public void onLoadFinished(Loader<Cursor> loader, Cursor cursor) {
mCursorAdapter.swapCursor(cursor);
}
#Override
public void onLoaderReset(Loader<Cursor> loader) {
mCursorAdapter.swapCursor(null);
}
}
PS: In the my manifest I didn't make it as the main launcher, since its only an activity after all.
What I am attempting to do is to open "Items" when the ImageButton "ibItem1" is pressed. But, after setting up this:
ibItem1.setOnClickListener(new OnClickListener() {
public void onClick(View arg0) {
Intent items = new Intent("android.intent.action.ITEMS");
startActivity(items);
}
});
And clicking the button does not do anything. I have the activity all set up in the manifest:
<activity
android:name="com.example.custombuilds.Items"
android:label="#string/app_name" >
<intent-filter>
<action android:name="android.intent.action.ITEMS" />
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
</activity>
The program has crashed before because of a ActivityNotFoundException, even though I declared it in the manifest.
Intent myIntent = new Intent(this, NextActivity.class);
startActivity(myIntent);
In this form, it should work..
Also make sure that the name of the class that implements the activity is the same in the manifest file at the android:name="atributevalue".The attribute value should be a fully qualified class name.
I am stumped, I get No Activity to handle intent, I have checked the manifest etc. Can someone have a quick look at this and see what I am doing wrong here.
This is my java class
'import com.one2.indoor.R;
import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.ImageButton;
public class Menu extends Activity {
#Override
protected void onCreate(Bundle savedInstanceState) {
// TODO Auto-generated method stub
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
ImageButton tut1 = (ImageButton) findViewById(R.id.activitymain);
tut1.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
// TODO Auto-generated method stub
startActivity (new Intent("com.indoor.ActivityMain"));
}
});
}'
This is my ActivityMain class
'import com.one2.indoor.R;
import android.app.Activity;
import android.os.Bundle;
public class ActivityMain extends Activity {
#Override
protected void onCreate(Bundle savedInstanceState) {
// TODO Auto-generated method stub
super.onCreate(savedInstanceState);
setContentView(R.layout.tutorial);
}
#Override
protected void onPause() {
// TODO Auto-generated method stub
super.onPause();
}
}'
and finally my manifest
'<activity
android:name="com.indoor.Main"
android:label="#string/app_name"
android:screenOrientation="portrait" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity
android:name="com.indoor.Menu"
android:label="#string/app_name"
android:screenOrientation="portrait" >
<intent-filter>
<action android:name="com.indoor.MENU" />
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
</activity>
<activity
android:name="com.indoor.ActivityMain"
android:label="#string/app_name"
android:screenOrientation="portrait" >
<intent-filter>
<action android:name="com.indoor.ACTIVITYMAIN" />
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
<meta-data
android:name="android.support.PARENT_ACTIVITY"
android:value="com.indoor.ActivityMain" />
</activity>
</application>
</manifest>
I just cant see it, why I'm getting the error. Any help be much appreciated
The path to your activity in the manifest and your startActivity is possibly incorrect. It should be com.one2.indoor.ActivityMain, or whatever is specified as its package.
Alternatively, I think you can just put .ActivityMain in the manifest for the name, and it will figure out the path automatically.
Finally, try using startActivity(new Intent(YourActivity.this, TargetActivity.class))
Like synergy8 said and you should accept his answer but you need a new intent in the android manifest declared by a new activity.
So to be more clear you should see your manifest have something like this sorry im doing this on a mobilr smart phone
<activity
android:label="#string/app_name"
android:name=".MainActivity" > //your activity name replaces .main activity
<intent-filter >
<action android:name="android.intent.action.MAIN" />
</intent-filter>
</activity>
That should do it, if you look at the first activity created there u will see it, just copy and paste it and changr the .main in the intent filter and the .mainactivity that it has in the activity
Basically from what I see and what synergy said you are importing a package that does not exist? Com.indoor.activity , when your package is com.one2.indoor.activity
First, action strings are case-sensitive. "com.indoor.ActivityMain" does not equal "com.indoor.ACTIVITYMAIN".
Second, you probably do not want those extra <intent-filter> elements anyway. Only put an <intent-filter> on an activity if you want third-party apps to invoke that activity directly (e.g., your MAIN/LAUNCHER activity). Otherwise, get rid of the <intent-filter> and use the Intent structure pointed out by Synergy807: startActivity(new Intent(this, ActivityMain.class))
I guess it will be com.one2.indoor.ActivityMain.Also make sure that the names should be exactly same as they are case sensitive.