标签: lifecycle

Android Activity-Lifecycle ...如何避免onDestroy()?

我有一个App,它使用ActicityGroup来拥有一堆Activity.如果我开始一个新的Activity,我这样做我的ActivityGroup的Child.让我们假设我在我的开始活动(1),我开始一个新的(2),所以这里是被调用的:

(1):onPause()

(2):onCreate(),onStart(),onResume()

直到这里,一切都如预期的那样.如果按下我的BackButton,堆栈如下:

(2):onPause(),onStop(),onDestroy()

(1):onStop(),onDestroy()[sic]

(1):onCreate(),onStart(),onResume()

我没有理由,首先为什么(1)应该执行onStop,而onDestroy()再次重新创建,以及为什么onRestart永远不会被调用(1).

有没有人有这种行为的理由?我可以以某种方式'取消'对onStop()或onDestroy()的调用吗?任何想法apreciated

lifecycle android activitygroup android-activity

1
推荐指数
1
解决办法
7127
查看次数

Android应用再次调用MAIN/LAUNCHER,而不是onResume()

当我的Android应用程序 - 活动B - 移动到后台(由用户按下android主页按钮),它仍然存活,onStop()被按预期调用.

活动B在这里没有被销毁,但是当用户再次点击应用程序的图标时,它再次调用intent-filter MAIN和LAUNCHER,启动活动A,而不是在活动B上调用onResume().

所以启动活动显示 - 活动A - ,但如果用户按下android后退按钮,则启动活动完成(),并显示旧活动 - 活动B - !

当活动B移动到后台时应该发生的事情是活动B暂停并停止.通过按应用程序图标恢复应用程序时,应恢复活动B. (除非它被杀死和摧毁,但它没有被杀死)

我该如何解决?活动B最初由活动A使用

Intent next = new Intent(ActivityA.this, ActivityB.class);
startActivity(next);
finish();
Run Code Online (Sandbox Code Playgroud)

这是活动B的清单条目

<activity android:name=".ActivityB"
    android:screenOrientation="portrait"
              android:label="@string/app_name"
              android:configChanges="orientation|keyboardHidden">
</activity>
Run Code Online (Sandbox Code Playgroud)

这是活动A的清单条目

<activity android:name=".Activity A"
     android:screenOrientation="portrait"
              android:label="@string/app_name"
              android:configChanges="orientation|keyboardHidden">
        <intent-filter>
            <action android:name="android.intent.action.MAIN" />
            <category android:name="android.intent.category.LAUNCHER" />
        </intent-filter>
</activity>
Run Code Online (Sandbox Code Playgroud)

为什么会发生这种情况,我该如何解决?

lifecycle android android-manifest

1
推荐指数
1
解决办法
1100
查看次数

Android生命周期活动

可能重复:
Android活动生命周期 - 这些方法有哪些?

我有一个主要叫做的活动menuActivity和另一个叫做的活动birthDate.

当我运行应用程序时,它menuActivity成为活动的应用程序,当我单击一个按钮时,第二个成为活动的应用程序birthDate.

我的问题是:

当第一个活动变为活动状态时,另一个活动转到后台,主要活动转到forground,我必须实现哪种方法?OnResume或者OnCreate还是什么?

lifecycle android onresume oncreate

1
推荐指数
1
解决办法
4120
查看次数

具有单线程执行程序的RESTful Web服务的体系结构?

我想知道什么是具有单线程执行程序的RESTful Web服务的最佳体系结构.

我的目标 :

  1. 调用RESTful Web服务
  2. Web服务在线程队列中添加任务,并按1执行所有任务1.

instanciated对象的生命周期非常重要(必须只有一个线程队列).我知道RESTful Web服务生命周期是"每个请求"(类似于我认为的@RequestScoped),所以我看到两个选项:

选项1 :

public class RestService {
    protected final static Executor executor;
    protected final static Implementation1 impl1;
    protected final static Implementation2 impl2;

    static {
        executor = Executors.newSingleThreadExecutor();
        impl1 = new Implementation1();
        impl2 = new Implementation2();
    }
}

@Path("/servicename")
public class MyService extends RestService {
    @POST
    @Path("/compute")
    public void compute(){
        executor.execute(new Runnable(){
            public void run(){
                impl1.compute();
            }
        });
    }
}
Run Code Online (Sandbox Code Playgroud)

选项2:

@Singleton
public class RestService {
    private Executor executor; …
Run Code Online (Sandbox Code Playgroud)

java rest lifecycle web-services executor

1
推荐指数
1
解决办法
1655
查看次数

android在片段中使用什么而不是onRestart()

我在app start的主片段中处理视图的 .setVisibility().所以我想要的是视图在应用程序启动时是不可见的(为此我在onCreateView中设置了INVISIBLE)并且当我在应用程序打开时从其他活动回到我的片段时可见:为此我尝试使用onRestart ()设置视图 VISIBLE但它无法解析onRestart方法)onRestart已弃用或?谢谢

编辑:对于以下所有建议使用onResume(并给出-1)的答案,onResume根本不作为onRestart工作,因为在onCreateView之后正在调用.

java lifecycle android oncreate

1
推荐指数
1
解决办法
5221
查看次数

验证成功后,UIInput#getValue()和getLocalValue()返回不同的值

在这里,它被作者提及。

如果[COMPONENT]标记为有效,则两者都返回相同的值,即提交,转换和验证的值。

考虑一个非常简单的代码段:

<h:form>
            <h:inputText value="#{bean.inputValue}" 
                         binding="#{bean.htmlInputText}"      
                         validator="nameValidator" /><br/>
            <h:commandButton value="Submit" action="#{bean.action}" />
</h:form>
Run Code Online (Sandbox Code Playgroud)

@RequestScoped支持豆-

public Integer inputValue = 5;
public HtmlInputText htmlInputText;

public void action(){
        System.out.println(" getSubmittedValue() "+htmlInputText.getSubmittedValue());
        System.out.println(" isLocalValueSet() "+ htmlInputText.isLocalValueSet());
        System.out.println(" getValue() " + htmlInputText.getValue());
        System.out.println(" getLocalValue() " +htmlInputText.getLocalValue());
}
Run Code Online (Sandbox Code Playgroud)

按下提交按钮后,输出为-

 getSubmittedValue() null    AS EXPECTED, since Conversion & Validation succeded
 isLocalValueSet() false
 getValue() 25               AS EXPECTED, since Conversion & Validation succeded
 getLocalValue() null        Why NULL? IN WHAT CONTEXT HAS THE AUTHOR SAID SO
Run Code Online (Sandbox Code Playgroud)

validation lifecycle jsf

1
推荐指数
1
解决办法
305
查看次数

ComponentWillMount仅在第一次触发?

MainComponent:

<Tabs 
  initialPage={this.props.day}
  tabBarUnderlineStyle={{ backgroundColor: '#5AF158' }} 
  renderTabBar={() => <ScrollableTab />}>
  {this.renderTabHeader()}
</Tabs>

renderTabHeader() {
  return (
    this.props.dateArray.map((date, i) => 
      <Tab 
        key={i}
        heading={date.format('DD/MM')} 
        tabStyle={styles.tabStyling} 
        activeTabStyle={styles.activeTabStyle} 
        textStyle={styles.tabTextStyle} 
        activeTextStyle={styles.activeTabTextStyle} 
      >
        <View style={{ backgroundColor: '#EEEEEE', flex: 1 }}>
          <Content contentDate={date.format('YYYY-MM-DD')} />
        </View>
      </Tab>
    )
  );
}
Run Code Online (Sandbox Code Playgroud)

内容组件:

class Content extends Component {
  componentWillMount() {
    console.log('Component Will Mount() ?');
    this.props.loadTransactionByDate({ date: this.props.contentDate });
  }

render() {
  return (
    <View><Text>{this.props.contentDate}</Text></View>
  );
  }
Run Code Online (Sandbox Code Playgroud)

基本上,在MainComponent中有一组选项卡.我注意到一些相当奇怪的东西Content会在他们的标签第一次点击或激活时安装?

这是第一次的意思,我们可以点击Tab索引2并看到控制台登录componentWillMount,然后我们切换到另一个选项卡,如果再次返回Tab索引2,componentWillMount将不再被触发?

lifecycle components react-native native-base

1
推荐指数
1
解决办法
2729
查看次数

为什么 ComponentShouldUpdate 会阻止评论渲染?

我在下面的代码中实现了 componentShouldUpdate 以尝试提高性能。这个目标已经实现,但现在评论没有呈现。但是,浏览器控制台显示正在接收所有内容。还有一个 div 呈现评论数量,并且也在更新。

            class ProposalDetail extends React.Component {
                      constructor(props) {
                        super(props);
                        this.state = {
                          sortedComments: []
                        };
                      }
                      componentDidUpdate(prevProps) {
                        if((!prevProps.proposal || Object.keys(prevProps.proposal).length === 0 ) &&
                          this.props.proposal && Object.keys(this.props.proposal).length > 0 &&
                          this.props.proposal.status === 4 ){
                          prevProps.onFetchProposalVoteStatus(prevProps.token);
                        }
                        this.handleUpdateOfComments(prevProps, this.props);
                      }
                      shouldComponentUpdate(nextProps, nextState) {
                        console.log('thisProps', this.props.comments)
                        console.log('nextProps', nextProps.comments)
                        if (this.props.comments === nextProps.comments) {
                            return true
                        }
                        else {
                            return false
                        }
                      }
                      componentDidMount() {
                        this.props.onFetchLikedComments(this.props.token);
                      }
                      componentWillUnmount() {
                        this.props.resetLastSubmittedProposal();
                      }
                      handleUpdateOfComments = (currentProps, nextProps) => {
                        let …
Run Code Online (Sandbox Code Playgroud)

javascript lifecycle reactjs

1
推荐指数
1
解决办法
6231
查看次数

从Vaadin 14开始寻找新的UI

Vaadin 14手册中的导航生命周期说:

也可以使用中的addBeforeEnterListener(BeforeEnterListener)方法为该事件注册一个独立的侦听器UI

但是在具有路由功能的现代Vaadin中,我们不再应该编写UI子类。我的粗略理解是确实存在一个UI为我们自动实例化的对象,然后路由自动替换了该UI对象中的内容。因此,UI对于使用Vaadin Flow的程序员来说,对象的存在应该是透明的。

?那么,新UI实例上的生命周期挂钩是什么,这样我就可以编写一个用户身份验证检查以BeforeEnterListener在所有@Route视图中全局工作?

调用UI.getCurrent不会做,因为我需要从布局中的某个地方调用它,但是我试图布局存在之前注册一个侦听器。

hook user-interface lifecycle vaadin vaadin-flow

1
推荐指数
1
解决办法
63
查看次数

组件之间对React生命周期事件顺序的保证是什么?

跨单独组件的React生命周期顺序有什么保证,并且在任何地方都清楚地记录了它们?

例如,假设我有:

<div>{ x ? <A /> : <B /> }</div>
Run Code Online (Sandbox Code Playgroud)

在这里,x在true和false之间进行更改将卸载一个组件,然后安装另一个组件。

是否可以保证安装所涉及的生命周期事件在这些元素上触发的顺序?

例如,有据可查的rendercomponentDidMountx更改为true 时,A会先于A 触发。但是,它保证rendercomponentDidMount对遗嘱后一直火componentWillUnmount对于B?

更进一步:如果A和B的孩子在这棵树的下方,并且开关位于顶部,是否会改变?

任何答案都欢迎,但是对此的坚定文件非常感谢。

javascript events lifecycle reactjs

1
推荐指数
1
解决办法
161
查看次数