这个让我难过.
我需要在自定义布局类中调用activity方法.这个问题是我不知道如何从布局中访问活动.
public class ProfileView extends LinearLayout
{
TextView profileTitleTextView;
ImageView profileScreenImageButton;
boolean isEmpty;
ProfileData data;
String name;
public ProfileView(Context context, AttributeSet attrs, String name, final ProfileData profileData)
{
super(context, attrs);
......
......
}
//Heres where things get complicated
public void onClick(View v)
{
//Need to get the parent activity and call its method.
ProfileActivity x = (ProfileActivity) context;
x.activityMethod();
}
}
Run Code Online (Sandbox Code Playgroud)
public class ProfileActivityActivity extends Activity
{
//In here I am creating multiple ProfileViews and adding them …Run Code Online (Sandbox Code Playgroud) 我有2个活动,Activity1和Activity2.
在Activity1我有一个按钮和TextView的.单击按钮时,将启动Activity2.
在Activity2我的EditText中.
我想显示从检索到的数据的EditText在活性2中的TextView在活性1当从压回活性2.
有人可以帮助我使用代码来完成这项工作吗?
将捆绑包传递给从当前活动中启动的活动的正确方法是什么?共享属性?
我想实现一个屏幕,Activity和所有其他sreens与Fragments和managing all the fragments thru the activity.
这是个好主意吗?我的答案是否定的,但我仍然想更清楚地了解这个想法.
这个想法的优点和缺点是什么?
注意:
请不要给我片段和活动的链接.
编辑:
这是碎片和活动的一部分:
优点:
缺点:
如果我们不考虑平板电脑,为什么要使用碎片?活动和片段之间的起始时间差是多少?
android android-layout android-lifecycle android-fragments android-activity
如何FLAG_ACTIVITY_NO_ANIMATION在AndroidManifest文件中正确使用Intent标志?我认为我的问题是微不足道的,但我找不到好的例子或解决方案.
<intent-filter>
<data android:name="android.content.Intent.FLAG_ACTIVITY_NO_ANIMATION" />
</intent-filter>
Run Code Online (Sandbox Code Playgroud)
但是,compliator没有报告错误,但是data不正确.我只想在活动之间切换时禁用动画.我可以getWindow().setWindowAnimations(0);在onCreate或onResume中使用,但使用flag是更好的方法,不是吗?
我也可以在代码中使用:
Intent intent = new Intent(v.getContext(), newactivity.class);
intent.addFlags(Intent.FLAG_ACTIVITY_NO_ANIMATION);
getContext().startActivity(intent);
Run Code Online (Sandbox Code Playgroud)
但是我想在Android Manifest中使用这个标志.如果从第二个活动返回到第一个活动,也要禁用动画.
我有一个带有通知的应用程序,如果我点击它们就会打开某个活动.我想要的是,如果我点击通知并且活动已经打开,它就不会再次启动,而是会被带到前面.
我以为我可以用国旗做FLAG_ACTIVITY_BROUGHT_TO_FRONT或FLAG_ACTIVITY_REORDER_TO_FRONT,但它一直再次打开它,所以我有两次活动.
这是我的代码:
event_notification = new Notification(R.drawable.icon,
mContext.getString(R.string.event_notif_message), System.currentTimeMillis());
Intent notificationIntent = new Intent(mContext, EventListActivity.class);
notificationIntent.setFlags(Intent.FLAG_ACTIVITY_BROUGHT_TO_FRONT);
sendNotification(event_notification, notificationIntent, mContext.getString(R.string.event_notif_title),
body, Utils.PA_NOTIFICATIONS_ID);
Run Code Online (Sandbox Code Playgroud)
我可以使用标志管理它,还是应该在SharedPreferences中存储变量以检查它是否已打开?
谢谢!
我想知道 - 和方法有什么区别?onCreate()onStart()
我认为这onStart()是一种多余的方法.onCreate()总是会被召唤(至少在我的最后两个项目中).
任何人都可以解释这个区别吗?
我正在使用电话从我的应用程序中的主要活动启动活动startActivityForResult(intent, ACTIVITY_TYPE),它们都在工作但只有一个.
这个,当被调用时,根据需要启动活动,但在日志中我可以看到它onActivityResult()立即被触发.活动显示但RESULT_CANCELED立即返回onActivityResult().
然后,我与活动互动,按下一个按钮,调用finish(),并且onActivityResult()不叫这个时候(因为很明显的结果已经返回).
这对任何人都有意义吗?以前有人见过这种行为吗?
有没有简单的方法来确定某项活动是否有效?我想根据哪些活动是活跃的来做某些事情.例如:
if(activityrunning == activity1)
//do this
else if (activityrunning == activity2)
//do something else
Run Code Online (Sandbox Code Playgroud) android ×10
android-activity ×10
animation ×1
bundle ×1
hierarchy ×1
oncreate ×1
onstart ×1
parent-child ×1
pass-data ×1
view ×1