Страница 5 из 5
Re: Урок 26. Intent Filter - практика
Добавлено: 27 июл 2015, 14:03
alex1
Сделал урок, время показывает, с датой возникли проблемы, когда добавил выбор вариантов активностей. Активность (любая, хоть базовая, хоть расширенная) с датой открывается, дата показывается корректно, но через пол-секунды-секунду эмулятор (4.0.3 API 15) перегружается. Пока выбора не было (одна активность с датой) - всё работало.
Долго думал, искал ошибку, не нашёл. Попробовал другую версию (4.4.2 API 19) - всё работает корректно.
Re: Урок 26. Intent Filter - практика
Добавлено: 08 дек 2015, 17:14
elaman16
При нажатии на Button - Show date не предлагается два варианта Activity, то есть не предлагает открыть через Date Basic или Date extended, а сразу открывает Date Basic.Хотя в коде все прописал . Использую Andriod Studio
MainActivity.java
Код: Выделить всё
package com.example.azamat.twoactivitystate;
import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
import android.support.design.widget.FloatingActionButton;
import android.support.design.widget.Snackbar;
import android.support.v7.app.AppCompatActivity;
import android.support.v7.widget.Toolbar;
import android.view.View;
import android.view.Menu;
import android.view.MenuItem;
import android.widget.Button;
import android.widget.Toast;
public class MainActivity extends AppCompatActivity implements View.OnClickListener {
Button btnTime;
Button btnDate;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
btnTime = (Button) findViewById(R.id.btnTime);
btnDate = (Button) findViewById(R.id.btnDate);
btnTime.setOnClickListener(this);
btnDate.setOnClickListener(this);
}
@Override
public void onClick(View v) {
Intent intent;
switch (v.getId()){
case R.id.btnTime:
intent = new Intent("com.example.intent.action.showtime");
startActivity(intent);
break;
case R.id.btnDate:
intent = new Intent("com.example.intent.action.showdate");
startActivity(intent);
break;
default:
Toast.makeText(this,"Не найден",Toast.LENGTH_LONG);
}
}
}
ActivityDate.java
Код: Выделить всё
package com.example.azamat.twoactivitystate;
import android.app.Activity;
import android.os.Bundle;
import android.support.design.widget.FloatingActionButton;
import android.support.design.widget.Snackbar;
import android.support.v7.app.AppCompatActivity;
import android.support.v7.widget.Toolbar;
import android.view.View;
import android.widget.TextView;
import java.text.SimpleDateFormat;
import java.util.Date;
public class ActivityDate extends Activity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.date);
SimpleDateFormat sdf = new SimpleDateFormat("dd.MM.yyyy");
String date = sdf.format(new Date(System.currentTimeMillis()));
TextView tvDate = (TextView) findViewById(R.id.tvDate);
tvDate.setText(date);
}
}
ActivityDataEx.java
Код: Выделить всё
package com.example.azamat.twoactivitystate;
import android.app.Activity;
import android.os.Bundle;
import android.support.design.widget.FloatingActionButton;
import android.support.design.widget.Snackbar;
import android.support.v7.app.AppCompatActivity;
import android.support.v7.widget.Toolbar;
import android.view.View;
import android.widget.TextView;
import java.text.SimpleDateFormat;
import java.util.Date;
public class ActivityDateEx extends Activity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.date);
SimpleDateFormat sdf = new SimpleDateFormat("EEE, MMM d, yyyy");
String date = sdf.format(new Date(System.currentTimeMillis()));
TextView tvDate = (TextView) findViewById(R.id.tvDate);
tvDate.setText(date);
}
}
AndroidManifest.xml
Код: Выделить всё
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.azamat.twoactivitystate" >
<application
android:allowBackup="true"
android:icon="@mipmap/ic_launcher"
android:label="@string/app_name"
android:supportsRtl="true"
android:theme="@style/AppTheme" >
<activity
android:name=".MainActivity"
android:label="@string/app_name"
android:theme="@style/AppTheme.NoActionBar" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity
android:name=".ActivityTime"
android:label="@string/title_activity_activity_time"
android:theme="@style/AppTheme.NoActionBar" >
<intent-filter>
<action android:name="com.example.intent.action.showtime" />
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
</activity>
<activity
android:name=".ActivityDate"
android:label="@string/title_activity_activity_date"
android:theme="@style/AppTheme.NoActionBar" >
<intent-filter>
<action android:name="com.example.intent.action.showdate" />
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
</activity>
<activity
android:name=".ActivityDateEx"
android:label="@string/title_activity_activity_date_ex"
android:theme="@style/AppTheme.NoActionBar" >
<action android:name="com.example.intent.action.showdate" />
<category android:name="android.intent.category.DEFAULT" />
</activity>
</application>
</manifest>
date.xml
Код: Выделить всё
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/tvDate"
android:text="TextView"
android:layout_gravity="center_horizontal"
android:layout_marginTop="20dp"
android:textSize="30sp">
</TextView>
</LinearLayout>
Re: Урок 26. Intent Filter - практика
Добавлено: 28 мар 2016, 07:55
AlMel
Друзья, простите за нубовский вопрос)
А как сделать чтобы кнопки по центру (горизонтально) располагались - через android:layout_gravity не получается?
Re: Урок 26. Intent Filter - практика
Добавлено: 10 авг 2016, 13:09
Ironhide
elaman16 писал(а):При нажатии на Button - Show date не предлагается два варианта Activity, то есть не предлагает открыть через Date Basic или Date extended, а сразу открывает Date Basic.Хотя в коде все прописал . Использую Andriod Studio
MainActivity.java
Код: Выделить всё
package com.example.azamat.twoactivitystate;
import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
import android.support.design.widget.FloatingActionButton;
import android.support.design.widget.Snackbar;
import android.support.v7.app.AppCompatActivity;
import android.support.v7.widget.Toolbar;
import android.view.View;
import android.view.Menu;
import android.view.MenuItem;
import android.widget.Button;
import android.widget.Toast;
public class MainActivity extends AppCompatActivity implements View.OnClickListener {
Button btnTime;
Button btnDate;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
btnTime = (Button) findViewById(R.id.btnTime);
btnDate = (Button) findViewById(R.id.btnDate);
btnTime.setOnClickListener(this);
btnDate.setOnClickListener(this);
}
@Override
public void onClick(View v) {
Intent intent;
switch (v.getId()){
case R.id.btnTime:
intent = new Intent("com.example.intent.action.showtime");
startActivity(intent);
break;
case R.id.btnDate:
intent = new Intent("com.example.intent.action.showdate");
startActivity(intent);
break;
default:
Toast.makeText(this,"Не найден",Toast.LENGTH_LONG);
}
}
}
ActivityDate.java
Код: Выделить всё
package com.example.azamat.twoactivitystate;
import android.app.Activity;
import android.os.Bundle;
import android.support.design.widget.FloatingActionButton;
import android.support.design.widget.Snackbar;
import android.support.v7.app.AppCompatActivity;
import android.support.v7.widget.Toolbar;
import android.view.View;
import android.widget.TextView;
import java.text.SimpleDateFormat;
import java.util.Date;
public class ActivityDate extends Activity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.date);
SimpleDateFormat sdf = new SimpleDateFormat("dd.MM.yyyy");
String date = sdf.format(new Date(System.currentTimeMillis()));
TextView tvDate = (TextView) findViewById(R.id.tvDate);
tvDate.setText(date);
}
}
ActivityDataEx.java
Код: Выделить всё
package com.example.azamat.twoactivitystate;
import android.app.Activity;
import android.os.Bundle;
import android.support.design.widget.FloatingActionButton;
import android.support.design.widget.Snackbar;
import android.support.v7.app.AppCompatActivity;
import android.support.v7.widget.Toolbar;
import android.view.View;
import android.widget.TextView;
import java.text.SimpleDateFormat;
import java.util.Date;
public class ActivityDateEx extends Activity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.date);
SimpleDateFormat sdf = new SimpleDateFormat("EEE, MMM d, yyyy");
String date = sdf.format(new Date(System.currentTimeMillis()));
TextView tvDate = (TextView) findViewById(R.id.tvDate);
tvDate.setText(date);
}
}
AndroidManifest.xml
Код: Выделить всё
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.azamat.twoactivitystate" >
<application
android:allowBackup="true"
android:icon="@mipmap/ic_launcher"
android:label="@string/app_name"
android:supportsRtl="true"
android:theme="@style/AppTheme" >
<activity
android:name=".MainActivity"
android:label="@string/app_name"
android:theme="@style/AppTheme.NoActionBar" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity
android:name=".ActivityTime"
android:label="@string/title_activity_activity_time"
android:theme="@style/AppTheme.NoActionBar" >
<intent-filter>
<action android:name="com.example.intent.action.showtime" />
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
</activity>
<activity
android:name=".ActivityDate"
android:label="@string/title_activity_activity_date"
android:theme="@style/AppTheme.NoActionBar" >
<intent-filter>
<action android:name="com.example.intent.action.showdate" />
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
</activity>
<activity
android:name=".ActivityDateEx"
android:label="@string/title_activity_activity_date_ex"
android:theme="@style/AppTheme.NoActionBar" >
<action android:name="com.example.intent.action.showdate" />
<category android:name="android.intent.category.DEFAULT" />
</activity>
</application>
</manifest>
date.xml
Код: Выделить всё
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/tvDate"
android:text="TextView"
android:layout_gravity="center_horizontal"
android:layout_marginTop="20dp"
android:textSize="30sp">
</TextView>
</LinearLayout>
Забыл intent Filter здесь
<activity
android:name=".ActivityDateEx"
android:label="@string/title_activity_activity_date_ex"
android:theme="@style/AppTheme.NoActionBar" >
<action android:name="com.example.intent.action.showdate" />
<category android:name="android.intent.category.DEFAULT" />
</activity>
Re: Урок 26. Intent Filter - практика
Добавлено: 16 дек 2016, 17:16
Foxy
Ребят, еще на стадии написания кода для TimeActivity.java столкнулся с проблемой.
Вот такая беда выскакивает на этой строке, пытался в манифесте прописать API другой - не получилось.
И в следующей же строке вот такая беда. В уроке ничего об этом нет
Re: Урок 26. Intent Filter - практика
Добавлено: 17 дек 2016, 12:32
Foxy
Окей, ответа не дождался, сделал проще
Код: Выделить всё
<DigitalClock
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:gravity="center"
android:textSize="20sp"/>
Re: Урок 26. Intent Filter - практика
Добавлено: 14 окт 2017, 18:05
magistr4815
Добрый день. Интересует, можно ли одному Activity_A добавить несколько РАЗНЫХ Intent Filter,
и при нажатии первой кнопки - переход осуществлялся в это Activity_A по 1 фильтру,
Activity_A определяло что это 1 фильтр и строило один макет (МАКЕТ_ОДИН).
Если вторая кнопка - то переход был по 2 фильтру в это же Activity_A, но Activity_A определяло,
что переход был по другому фильтру и строило уже другой макет (МАКЕТ_ДВА)?
Т.е. избежать постройки множества активити, а сделать по сути только два - Главное
(на котором несколько кнопок) и второе (которое динамически изменяется в зависимости от перехода)?
И вообще есть ли в этом смысл?
Надеюсь я понятно изложил.
Заранее спасибо)
Re: Урок 26. Intent Filter - практика
Добавлено: 27 фев 2020, 13:57
atos
Добрый день! Использую андроид 3.5.3 и думаю многое поменялось так как не могу найти этот кусок кода в программе
После того, как прописали в манифесте, надо будет там же создать Intent Filter. Для этого выделяем ActivityTime, жмем Add, выбираем Intent Filter и жмем ОК.
Далее идет окно Application Nodes которые вообще не смог найти. Кто знает как его реализовать в Андроид 3.5.3
Re: Урок 26. Intent Filter - практика
Добавлено: 20 апр 2020, 20:06
Skleptik
Поддерживаю вопрос...Уроки при царе горохе написаны, обновите пожалуйста материал, а то на простые вещи уходят часы поиска.
Re: Урок 26. Intent Filter - практика
Добавлено: 16 авг 2020, 17:02
Martovsky
Если чуть чуть погуглить, то все проходится спокойно. Времени действительно много прошло, но не сильно все и изменилось.
Re: Урок 26. Intent Filter - практика
Добавлено: 08 дек 2021, 21:54
Zimnika
Необходимо добавить в AndroidManifest.xml :
внутри тега activity
Код: Выделить всё
<intent-filter>
<action android:name="ru.startandroid.intent.action.showtime" />
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
и
Код: Выделить всё
<intent-filter>
<action android:name="ru.startandroid.intent.action.showtime" />
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
т.е. итого у вас будет:
Код: Выделить всё
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.p0261_intentfilter">
<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/Theme.LessonsAndroid">
<activity
android:name=".ActivityDate"
android:exported="false">
<intent-filter>
<action android:name="ru.startandroid.intent.action.showdate" />
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
</activity>
<activity
android:name=".ActivityTime"
android:exported="false">
<intent-filter>
<action android:name="ru.startandroid.intent.action.showtime" />
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
</activity>
<activity
android:name=".MainActivity"
android:exported="true">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>
</manifest>